Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/kaber/nf-next-2.6
[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 int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
442                            struct ieee80211_vif *vif,
443                            struct ieee80211_sta *sta,
444                            enum ieee80211_ampdu_mlme_action action, u16 tid)
445 {
446         struct ath_common *common = ath9k_hw_common(priv->ah);
447         struct ath9k_htc_target_aggr aggr;
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         ista = (struct ath9k_htc_sta *) sta->drv_priv;
457
458         aggr.sta_index = ista->index;
459         aggr.tidno = tid & 0xf;
460         aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
461
462         WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
463         if (ret)
464                 ath_print(common, ATH_DBG_CONFIG,
465                           "Unable to %s TX aggregation for (%pM, %d)\n",
466                           (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
467         else
468                 ath_print(common, ATH_DBG_CONFIG,
469                           "%s TX aggregation for (%pM, %d)\n",
470                           (aggr.aggr_enable) ? "Starting" : "Stopping",
471                           sta->addr, tid);
472
473         spin_lock_bh(&priv->tx_lock);
474         ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
475         spin_unlock_bh(&priv->tx_lock);
476
477         return ret;
478 }
479
480 /*********/
481 /* DEBUG */
482 /*********/
483
484 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
485
486 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
487 {
488         file->private_data = inode->i_private;
489         return 0;
490 }
491
492 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
493                                    size_t count, loff_t *ppos)
494 {
495         struct ath9k_htc_priv *priv =
496                 (struct ath9k_htc_priv *) file->private_data;
497         struct ath9k_htc_target_stats cmd_rsp;
498         char buf[512];
499         unsigned int len = 0;
500         int ret = 0;
501
502         memset(&cmd_rsp, 0, sizeof(cmd_rsp));
503
504         WMI_CMD(WMI_TGT_STATS_CMDID);
505         if (ret)
506                 return -EINVAL;
507
508
509         len += snprintf(buf + len, sizeof(buf) - len,
510                         "%19s : %10u\n", "TX Short Retries",
511                         be32_to_cpu(cmd_rsp.tx_shortretry));
512         len += snprintf(buf + len, sizeof(buf) - len,
513                         "%19s : %10u\n", "TX Long Retries",
514                         be32_to_cpu(cmd_rsp.tx_longretry));
515         len += snprintf(buf + len, sizeof(buf) - len,
516                         "%19s : %10u\n", "TX Xretries",
517                         be32_to_cpu(cmd_rsp.tx_xretries));
518         len += snprintf(buf + len, sizeof(buf) - len,
519                         "%19s : %10u\n", "TX Unaggr. Xretries",
520                         be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
521         len += snprintf(buf + len, sizeof(buf) - len,
522                         "%19s : %10u\n", "TX Xretries (HT)",
523                         be32_to_cpu(cmd_rsp.ht_tx_xretries));
524         len += snprintf(buf + len, sizeof(buf) - len,
525                         "%19s : %10u\n", "TX Rate", priv->debug.txrate);
526
527         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
528 }
529
530 static const struct file_operations fops_tgt_stats = {
531         .read = read_file_tgt_stats,
532         .open = ath9k_debugfs_open,
533         .owner = THIS_MODULE
534 };
535
536 static ssize_t read_file_xmit(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         char buf[512];
542         unsigned int len = 0;
543
544         len += snprintf(buf + len, sizeof(buf) - len,
545                         "%20s : %10u\n", "Buffers queued",
546                         priv->debug.tx_stats.buf_queued);
547         len += snprintf(buf + len, sizeof(buf) - len,
548                         "%20s : %10u\n", "Buffers completed",
549                         priv->debug.tx_stats.buf_completed);
550         len += snprintf(buf + len, sizeof(buf) - len,
551                         "%20s : %10u\n", "SKBs queued",
552                         priv->debug.tx_stats.skb_queued);
553         len += snprintf(buf + len, sizeof(buf) - len,
554                         "%20s : %10u\n", "SKBs completed",
555                         priv->debug.tx_stats.skb_completed);
556         len += snprintf(buf + len, sizeof(buf) - len,
557                         "%20s : %10u\n", "SKBs dropped",
558                         priv->debug.tx_stats.skb_dropped);
559
560         len += snprintf(buf + len, sizeof(buf) - len,
561                         "%20s : %10u\n", "BE queued",
562                         priv->debug.tx_stats.queue_stats[WME_AC_BE]);
563         len += snprintf(buf + len, sizeof(buf) - len,
564                         "%20s : %10u\n", "BK queued",
565                         priv->debug.tx_stats.queue_stats[WME_AC_BK]);
566         len += snprintf(buf + len, sizeof(buf) - len,
567                         "%20s : %10u\n", "VI queued",
568                         priv->debug.tx_stats.queue_stats[WME_AC_VI]);
569         len += snprintf(buf + len, sizeof(buf) - len,
570                         "%20s : %10u\n", "VO queued",
571                         priv->debug.tx_stats.queue_stats[WME_AC_VO]);
572
573         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
574 }
575
576 static const struct file_operations fops_xmit = {
577         .read = read_file_xmit,
578         .open = ath9k_debugfs_open,
579         .owner = THIS_MODULE
580 };
581
582 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
583                               size_t count, loff_t *ppos)
584 {
585         struct ath9k_htc_priv *priv =
586                 (struct ath9k_htc_priv *) file->private_data;
587         char buf[512];
588         unsigned int len = 0;
589
590         len += snprintf(buf + len, sizeof(buf) - len,
591                         "%20s : %10u\n", "SKBs allocated",
592                         priv->debug.rx_stats.skb_allocated);
593         len += snprintf(buf + len, sizeof(buf) - len,
594                         "%20s : %10u\n", "SKBs completed",
595                         priv->debug.rx_stats.skb_completed);
596         len += snprintf(buf + len, sizeof(buf) - len,
597                         "%20s : %10u\n", "SKBs Dropped",
598                         priv->debug.rx_stats.skb_dropped);
599
600         return simple_read_from_buffer(user_buf, count, ppos, buf, len);
601 }
602
603 static const struct file_operations fops_recv = {
604         .read = read_file_recv,
605         .open = ath9k_debugfs_open,
606         .owner = THIS_MODULE
607 };
608
609 int ath9k_htc_init_debug(struct ath_hw *ah)
610 {
611         struct ath_common *common = ath9k_hw_common(ah);
612         struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
613
614         if (!ath9k_debugfs_root)
615                 return -ENOENT;
616
617         priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
618                                                      ath9k_debugfs_root);
619         if (!priv->debug.debugfs_phy)
620                 goto err;
621
622         priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
623                                                     priv->debug.debugfs_phy,
624                                                     priv, &fops_tgt_stats);
625         if (!priv->debug.debugfs_tgt_stats)
626                 goto err;
627
628
629         priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
630                                                        priv->debug.debugfs_phy,
631                                                        priv, &fops_xmit);
632         if (!priv->debug.debugfs_xmit)
633                 goto err;
634
635         priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
636                                                        priv->debug.debugfs_phy,
637                                                        priv, &fops_recv);
638         if (!priv->debug.debugfs_recv)
639                 goto err;
640
641         return 0;
642
643 err:
644         ath9k_htc_exit_debug(ah);
645         return -ENOMEM;
646 }
647
648 void ath9k_htc_exit_debug(struct ath_hw *ah)
649 {
650         struct ath_common *common = ath9k_hw_common(ah);
651         struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
652
653         debugfs_remove(priv->debug.debugfs_recv);
654         debugfs_remove(priv->debug.debugfs_xmit);
655         debugfs_remove(priv->debug.debugfs_tgt_stats);
656         debugfs_remove(priv->debug.debugfs_phy);
657 }
658
659 int ath9k_htc_debug_create_root(void)
660 {
661         ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
662         if (!ath9k_debugfs_root)
663                 return -ENOENT;
664
665         return 0;
666 }
667
668 void ath9k_htc_debug_remove_root(void)
669 {
670         debugfs_remove(ath9k_debugfs_root);
671         ath9k_debugfs_root = NULL;
672 }
673
674 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
675
676 /*******/
677 /* ANI */
678 /*******/
679
680 static void ath_start_ani(struct ath9k_htc_priv *priv)
681 {
682         struct ath_common *common = ath9k_hw_common(priv->ah);
683         unsigned long timestamp = jiffies_to_msecs(jiffies);
684
685         common->ani.longcal_timer = timestamp;
686         common->ani.shortcal_timer = timestamp;
687         common->ani.checkani_timer = timestamp;
688
689         ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
690                                      msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
691 }
692
693 void ath9k_ani_work(struct work_struct *work)
694 {
695         struct ath9k_htc_priv *priv =
696                 container_of(work, struct ath9k_htc_priv,
697                              ath9k_ani_work.work);
698         struct ath_hw *ah = priv->ah;
699         struct ath_common *common = ath9k_hw_common(ah);
700         bool longcal = false;
701         bool shortcal = false;
702         bool aniflag = false;
703         unsigned int timestamp = jiffies_to_msecs(jiffies);
704         u32 cal_interval, short_cal_interval;
705
706         short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
707
708         /* Only calibrate if awake */
709         if (ah->power_mode != ATH9K_PM_AWAKE)
710                 goto set_timer;
711
712         /* Long calibration runs independently of short calibration. */
713         if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
714                 longcal = true;
715                 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
716                 common->ani.longcal_timer = timestamp;
717         }
718
719         /* Short calibration applies only while caldone is false */
720         if (!common->ani.caldone) {
721                 if ((timestamp - common->ani.shortcal_timer) >=
722                     short_cal_interval) {
723                         shortcal = true;
724                         ath_print(common, ATH_DBG_ANI,
725                                   "shortcal @%lu\n", jiffies);
726                         common->ani.shortcal_timer = timestamp;
727                         common->ani.resetcal_timer = timestamp;
728                 }
729         } else {
730                 if ((timestamp - common->ani.resetcal_timer) >=
731                     ATH_RESTART_CALINTERVAL) {
732                         common->ani.caldone = ath9k_hw_reset_calvalid(ah);
733                         if (common->ani.caldone)
734                                 common->ani.resetcal_timer = timestamp;
735                 }
736         }
737
738         /* Verify whether we must check ANI */
739         if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
740                 aniflag = true;
741                 common->ani.checkani_timer = timestamp;
742         }
743
744         /* Skip all processing if there's nothing to do. */
745         if (longcal || shortcal || aniflag) {
746
747                 ath9k_htc_ps_wakeup(priv);
748
749                 /* Call ANI routine if necessary */
750                 if (aniflag)
751                         ath9k_hw_ani_monitor(ah, ah->curchan);
752
753                 /* Perform calibration if necessary */
754                 if (longcal || shortcal) {
755                         common->ani.caldone =
756                                 ath9k_hw_calibrate(ah, ah->curchan,
757                                                    common->rx_chainmask,
758                                                    longcal);
759
760                         if (longcal)
761                                 common->ani.noise_floor =
762                                         ath9k_hw_getchan_noise(ah, ah->curchan);
763
764                         ath_print(common, ATH_DBG_ANI,
765                                   " calibrate chan %u/%x nf: %d\n",
766                                   ah->curchan->channel,
767                                   ah->curchan->channelFlags,
768                                   common->ani.noise_floor);
769                 }
770
771                 ath9k_htc_ps_restore(priv);
772         }
773
774 set_timer:
775         /*
776         * Set timer interval based on previous results.
777         * The interval must be the shortest necessary to satisfy ANI,
778         * short calibration and long calibration.
779         */
780         cal_interval = ATH_LONG_CALINTERVAL;
781         if (priv->ah->config.enable_ani)
782                 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
783         if (!common->ani.caldone)
784                 cal_interval = min(cal_interval, (u32)short_cal_interval);
785
786         ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
787                                      msecs_to_jiffies(cal_interval));
788 }
789
790 /*******/
791 /* LED */
792 /*******/
793
794 static void ath9k_led_blink_work(struct work_struct *work)
795 {
796         struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
797                                                    ath9k_led_blink_work.work);
798
799         if (!(priv->op_flags & OP_LED_ASSOCIATED))
800                 return;
801
802         if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
803             (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
804                 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
805         else
806                 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
807                                   (priv->op_flags & OP_LED_ON) ? 1 : 0);
808
809         ieee80211_queue_delayed_work(priv->hw,
810                                      &priv->ath9k_led_blink_work,
811                                      (priv->op_flags & OP_LED_ON) ?
812                                      msecs_to_jiffies(priv->led_off_duration) :
813                                      msecs_to_jiffies(priv->led_on_duration));
814
815         priv->led_on_duration = priv->led_on_cnt ?
816                 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
817                 ATH_LED_ON_DURATION_IDLE;
818         priv->led_off_duration = priv->led_off_cnt ?
819                 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
820                 ATH_LED_OFF_DURATION_IDLE;
821         priv->led_on_cnt = priv->led_off_cnt = 0;
822
823         if (priv->op_flags & OP_LED_ON)
824                 priv->op_flags &= ~OP_LED_ON;
825         else
826                 priv->op_flags |= OP_LED_ON;
827 }
828
829 static void ath9k_led_brightness_work(struct work_struct *work)
830 {
831         struct ath_led *led = container_of(work, struct ath_led,
832                                            brightness_work.work);
833         struct ath9k_htc_priv *priv = led->priv;
834
835         switch (led->brightness) {
836         case LED_OFF:
837                 if (led->led_type == ATH_LED_ASSOC ||
838                     led->led_type == ATH_LED_RADIO) {
839                         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
840                                           (led->led_type == ATH_LED_RADIO));
841                         priv->op_flags &= ~OP_LED_ASSOCIATED;
842                         if (led->led_type == ATH_LED_RADIO)
843                                 priv->op_flags &= ~OP_LED_ON;
844                 } else {
845                         priv->led_off_cnt++;
846                 }
847                 break;
848         case LED_FULL:
849                 if (led->led_type == ATH_LED_ASSOC) {
850                         priv->op_flags |= OP_LED_ASSOCIATED;
851                         ieee80211_queue_delayed_work(priv->hw,
852                                              &priv->ath9k_led_blink_work, 0);
853                 } else if (led->led_type == ATH_LED_RADIO) {
854                         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
855                         priv->op_flags |= OP_LED_ON;
856                 } else {
857                         priv->led_on_cnt++;
858                 }
859                 break;
860         default:
861                 break;
862         }
863 }
864
865 static void ath9k_led_brightness(struct led_classdev *led_cdev,
866                                  enum led_brightness brightness)
867 {
868         struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
869         struct ath9k_htc_priv *priv = led->priv;
870
871         led->brightness = brightness;
872         if (!(priv->op_flags & OP_LED_DEINIT))
873                 ieee80211_queue_delayed_work(priv->hw,
874                                              &led->brightness_work, 0);
875 }
876
877 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
878 {
879         cancel_delayed_work_sync(&priv->radio_led.brightness_work);
880         cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
881         cancel_delayed_work_sync(&priv->tx_led.brightness_work);
882         cancel_delayed_work_sync(&priv->rx_led.brightness_work);
883 }
884
885 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
886                               char *trigger)
887 {
888         int ret;
889
890         led->priv = priv;
891         led->led_cdev.name = led->name;
892         led->led_cdev.default_trigger = trigger;
893         led->led_cdev.brightness_set = ath9k_led_brightness;
894
895         ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
896         if (ret)
897                 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
898                           "Failed to register led:%s", led->name);
899         else
900                 led->registered = 1;
901
902         INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
903
904         return ret;
905 }
906
907 static void ath9k_unregister_led(struct ath_led *led)
908 {
909         if (led->registered) {
910                 led_classdev_unregister(&led->led_cdev);
911                 led->registered = 0;
912         }
913 }
914
915 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
916 {
917         priv->op_flags |= OP_LED_DEINIT;
918         ath9k_unregister_led(&priv->assoc_led);
919         priv->op_flags &= ~OP_LED_ASSOCIATED;
920         ath9k_unregister_led(&priv->tx_led);
921         ath9k_unregister_led(&priv->rx_led);
922         ath9k_unregister_led(&priv->radio_led);
923 }
924
925 void ath9k_init_leds(struct ath9k_htc_priv *priv)
926 {
927         char *trigger;
928         int ret;
929
930         if (AR_SREV_9287(priv->ah))
931                 priv->ah->led_pin = ATH_LED_PIN_9287;
932         else if (AR_SREV_9271(priv->ah))
933                 priv->ah->led_pin = ATH_LED_PIN_9271;
934         else if (AR_DEVID_7010(priv->ah))
935                 priv->ah->led_pin = ATH_LED_PIN_7010;
936         else
937                 priv->ah->led_pin = ATH_LED_PIN_DEF;
938
939         /* Configure gpio 1 for output */
940         ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
941                             AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
942         /* LED off, active low */
943         ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
944
945         INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
946
947         trigger = ieee80211_get_radio_led_name(priv->hw);
948         snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
949                 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
950         ret = ath9k_register_led(priv, &priv->radio_led, trigger);
951         priv->radio_led.led_type = ATH_LED_RADIO;
952         if (ret)
953                 goto fail;
954
955         trigger = ieee80211_get_assoc_led_name(priv->hw);
956         snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
957                 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
958         ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
959         priv->assoc_led.led_type = ATH_LED_ASSOC;
960         if (ret)
961                 goto fail;
962
963         trigger = ieee80211_get_tx_led_name(priv->hw);
964         snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
965                 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
966         ret = ath9k_register_led(priv, &priv->tx_led, trigger);
967         priv->tx_led.led_type = ATH_LED_TX;
968         if (ret)
969                 goto fail;
970
971         trigger = ieee80211_get_rx_led_name(priv->hw);
972         snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
973                 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
974         ret = ath9k_register_led(priv, &priv->rx_led, trigger);
975         priv->rx_led.led_type = ATH_LED_RX;
976         if (ret)
977                 goto fail;
978
979         priv->op_flags &= ~OP_LED_DEINIT;
980
981         return;
982
983 fail:
984         cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
985         ath9k_deinit_leds(priv);
986 }
987
988 /*******************/
989 /*      Rfkill     */
990 /*******************/
991
992 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
993 {
994         return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
995                 priv->ah->rfkill_polarity;
996 }
997
998 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
999 {
1000         struct ath9k_htc_priv *priv = hw->priv;
1001         bool blocked = !!ath_is_rfkill_set(priv);
1002
1003         wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1004 }
1005
1006 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1007 {
1008         if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1009                 wiphy_rfkill_start_polling(priv->hw->wiphy);
1010 }
1011
1012 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1013 {
1014         struct ath9k_htc_priv *priv = hw->priv;
1015         struct ath_hw *ah = priv->ah;
1016         struct ath_common *common = ath9k_hw_common(ah);
1017         int ret;
1018         u8 cmd_rsp;
1019
1020         if (!ah->curchan)
1021                 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1022
1023         /* Reset the HW */
1024         ret = ath9k_hw_reset(ah, ah->curchan, false);
1025         if (ret) {
1026                 ath_print(common, ATH_DBG_FATAL,
1027                           "Unable to reset hardware; reset status %d "
1028                           "(freq %u MHz)\n", ret, ah->curchan->channel);
1029         }
1030
1031         ath_update_txpow(priv);
1032
1033         /* Start RX */
1034         WMI_CMD(WMI_START_RECV_CMDID);
1035         ath9k_host_rx_init(priv);
1036
1037         /* Start TX */
1038         htc_start(priv->htc);
1039         spin_lock_bh(&priv->tx_lock);
1040         priv->tx_queues_stop = false;
1041         spin_unlock_bh(&priv->tx_lock);
1042         ieee80211_wake_queues(hw);
1043
1044         WMI_CMD(WMI_ENABLE_INTR_CMDID);
1045
1046         /* Enable LED */
1047         ath9k_hw_cfg_output(ah, ah->led_pin,
1048                             AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1049         ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1050 }
1051
1052 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1053 {
1054         struct ath9k_htc_priv *priv = hw->priv;
1055         struct ath_hw *ah = priv->ah;
1056         struct ath_common *common = ath9k_hw_common(ah);
1057         int ret;
1058         u8 cmd_rsp;
1059
1060         ath9k_htc_ps_wakeup(priv);
1061
1062         /* Disable LED */
1063         ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1064         ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1065
1066         WMI_CMD(WMI_DISABLE_INTR_CMDID);
1067
1068         /* Stop TX */
1069         ieee80211_stop_queues(hw);
1070         htc_stop(priv->htc);
1071         WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1072         skb_queue_purge(&priv->tx_queue);
1073
1074         /* Stop RX */
1075         WMI_CMD(WMI_STOP_RECV_CMDID);
1076
1077         /*
1078          * The MIB counters have to be disabled here,
1079          * since the target doesn't do it.
1080          */
1081         ath9k_hw_disable_mib_counters(ah);
1082
1083         if (!ah->curchan)
1084                 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1085
1086         /* Reset the HW */
1087         ret = ath9k_hw_reset(ah, ah->curchan, false);
1088         if (ret) {
1089                 ath_print(common, ATH_DBG_FATAL,
1090                           "Unable to reset hardware; reset status %d "
1091                           "(freq %u MHz)\n", ret, ah->curchan->channel);
1092         }
1093
1094         /* Disable the PHY */
1095         ath9k_hw_phy_disable(ah);
1096
1097         ath9k_htc_ps_restore(priv);
1098         ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1099 }
1100
1101 /**********************/
1102 /* mac80211 Callbacks */
1103 /**********************/
1104
1105 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1106 {
1107         struct ieee80211_hdr *hdr;
1108         struct ath9k_htc_priv *priv = hw->priv;
1109         int padpos, padsize, ret;
1110
1111         hdr = (struct ieee80211_hdr *) skb->data;
1112
1113         /* Add the padding after the header if this is not already done */
1114         padpos = ath9k_cmn_padpos(hdr->frame_control);
1115         padsize = padpos & 3;
1116         if (padsize && skb->len > padpos) {
1117                 if (skb_headroom(skb) < padsize)
1118                         return -1;
1119                 skb_push(skb, padsize);
1120                 memmove(skb->data, skb->data + padsize, padpos);
1121         }
1122
1123         ret = ath9k_htc_tx_start(priv, skb);
1124         if (ret != 0) {
1125                 if (ret == -ENOMEM) {
1126                         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1127                                   "Stopping TX queues\n");
1128                         ieee80211_stop_queues(hw);
1129                         spin_lock_bh(&priv->tx_lock);
1130                         priv->tx_queues_stop = true;
1131                         spin_unlock_bh(&priv->tx_lock);
1132                 } else {
1133                         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1134                                   "Tx failed");
1135                 }
1136                 goto fail_tx;
1137         }
1138
1139         return 0;
1140
1141 fail_tx:
1142         dev_kfree_skb_any(skb);
1143         return 0;
1144 }
1145
1146 static int ath9k_htc_start(struct ieee80211_hw *hw)
1147 {
1148         struct ath9k_htc_priv *priv = hw->priv;
1149         struct ath_hw *ah = priv->ah;
1150         struct ath_common *common = ath9k_hw_common(ah);
1151         struct ieee80211_channel *curchan = hw->conf.channel;
1152         struct ath9k_channel *init_channel;
1153         int ret = 0;
1154         enum htc_phymode mode;
1155         __be16 htc_mode;
1156         u8 cmd_rsp;
1157
1158         mutex_lock(&priv->mutex);
1159
1160         ath_print(common, ATH_DBG_CONFIG,
1161                   "Starting driver with initial channel: %d MHz\n",
1162                   curchan->center_freq);
1163
1164         /* Ensure that HW is awake before flushing RX */
1165         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1166         WMI_CMD(WMI_FLUSH_RECV_CMDID);
1167
1168         /* setup initial channel */
1169         init_channel = ath9k_cmn_get_curchannel(hw, ah);
1170
1171         /* Reset SERDES registers */
1172         ath9k_hw_configpcipowersave(ah, 0, 0);
1173
1174         ath9k_hw_htc_resetinit(ah);
1175         ret = ath9k_hw_reset(ah, init_channel, false);
1176         if (ret) {
1177                 ath_print(common, ATH_DBG_FATAL,
1178                           "Unable to reset hardware; reset status %d "
1179                           "(freq %u MHz)\n", ret, curchan->center_freq);
1180                 mutex_unlock(&priv->mutex);
1181                 return ret;
1182         }
1183
1184         ath_update_txpow(priv);
1185
1186         mode = ath9k_htc_get_curmode(priv, init_channel);
1187         htc_mode = cpu_to_be16(mode);
1188         WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1189         WMI_CMD(WMI_ATH_INIT_CMDID);
1190         WMI_CMD(WMI_START_RECV_CMDID);
1191
1192         ath9k_host_rx_init(priv);
1193
1194         priv->op_flags &= ~OP_INVALID;
1195         htc_start(priv->htc);
1196
1197         spin_lock_bh(&priv->tx_lock);
1198         priv->tx_queues_stop = false;
1199         spin_unlock_bh(&priv->tx_lock);
1200
1201         ieee80211_wake_queues(hw);
1202
1203         mutex_unlock(&priv->mutex);
1204
1205         return ret;
1206 }
1207
1208 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1209 {
1210         struct ath9k_htc_priv *priv = hw->priv;
1211         struct ath_hw *ah = priv->ah;
1212         struct ath_common *common = ath9k_hw_common(ah);
1213         int ret = 0;
1214         u8 cmd_rsp;
1215
1216         mutex_lock(&priv->mutex);
1217
1218         if (priv->op_flags & OP_INVALID) {
1219                 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1220                 mutex_unlock(&priv->mutex);
1221                 return;
1222         }
1223
1224         /* Cancel all the running timers/work .. */
1225         cancel_work_sync(&priv->ps_work);
1226         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1227         cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1228         ath9k_led_stop_brightness(priv);
1229
1230         ath9k_htc_ps_wakeup(priv);
1231         htc_stop(priv->htc);
1232         WMI_CMD(WMI_DISABLE_INTR_CMDID);
1233         WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1234         WMI_CMD(WMI_STOP_RECV_CMDID);
1235         skb_queue_purge(&priv->tx_queue);
1236
1237         /* Remove monitor interface here */
1238         if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1239                 if (ath9k_htc_remove_monitor_interface(priv))
1240                         ath_print(common, ATH_DBG_FATAL,
1241                                   "Unable to remove monitor interface\n");
1242                 else
1243                         ath_print(common, ATH_DBG_CONFIG,
1244                                   "Monitor interface removed\n");
1245         }
1246
1247         ath9k_hw_phy_disable(ah);
1248         ath9k_hw_disable(ah);
1249         ath9k_hw_configpcipowersave(ah, 1, 1);
1250         ath9k_htc_ps_restore(priv);
1251         ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1252
1253         priv->op_flags |= OP_INVALID;
1254
1255         ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1256         mutex_unlock(&priv->mutex);
1257 }
1258
1259 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1260                                    struct ieee80211_vif *vif)
1261 {
1262         struct ath9k_htc_priv *priv = hw->priv;
1263         struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1264         struct ath_common *common = ath9k_hw_common(priv->ah);
1265         struct ath9k_htc_target_vif hvif;
1266         int ret = 0;
1267         u8 cmd_rsp;
1268
1269         mutex_lock(&priv->mutex);
1270
1271         /* Only one interface for now */
1272         if (priv->nvifs > 0) {
1273                 ret = -ENOBUFS;
1274                 goto out;
1275         }
1276
1277         ath9k_htc_ps_wakeup(priv);
1278         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1279         memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1280
1281         switch (vif->type) {
1282         case NL80211_IFTYPE_STATION:
1283                 hvif.opmode = cpu_to_be32(HTC_M_STA);
1284                 break;
1285         case NL80211_IFTYPE_ADHOC:
1286                 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1287                 break;
1288         default:
1289                 ath_print(common, ATH_DBG_FATAL,
1290                         "Interface type %d not yet supported\n", vif->type);
1291                 ret = -EOPNOTSUPP;
1292                 goto out;
1293         }
1294
1295         ath_print(common, ATH_DBG_CONFIG,
1296                   "Attach a VIF of type: %d\n", vif->type);
1297
1298         priv->ah->opmode = vif->type;
1299
1300         /* Index starts from zero on the target */
1301         avp->index = hvif.index = priv->nvifs;
1302         hvif.rtsthreshold = cpu_to_be16(2304);
1303         WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1304         if (ret)
1305                 goto out;
1306
1307         priv->nvifs++;
1308
1309         /*
1310          * We need a node in target to tx mgmt frames
1311          * before association.
1312          */
1313         ret = ath9k_htc_add_station(priv, vif, NULL);
1314         if (ret)
1315                 goto out;
1316
1317         ret = ath9k_htc_update_cap_target(priv);
1318         if (ret)
1319                 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1320                           " capability in target \n");
1321
1322         priv->vif = vif;
1323 out:
1324         ath9k_htc_ps_restore(priv);
1325         mutex_unlock(&priv->mutex);
1326
1327         return ret;
1328 }
1329
1330 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1331                                        struct ieee80211_vif *vif)
1332 {
1333         struct ath9k_htc_priv *priv = hw->priv;
1334         struct ath_common *common = ath9k_hw_common(priv->ah);
1335         struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1336         struct ath9k_htc_target_vif hvif;
1337         int ret = 0;
1338         u8 cmd_rsp;
1339
1340         ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1341
1342         mutex_lock(&priv->mutex);
1343         ath9k_htc_ps_wakeup(priv);
1344
1345         memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1346         memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1347         hvif.index = avp->index;
1348         WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1349         priv->nvifs--;
1350
1351         ath9k_htc_remove_station(priv, vif, NULL);
1352         priv->vif = NULL;
1353
1354         ath9k_htc_ps_restore(priv);
1355         mutex_unlock(&priv->mutex);
1356 }
1357
1358 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1359 {
1360         struct ath9k_htc_priv *priv = hw->priv;
1361         struct ath_common *common = ath9k_hw_common(priv->ah);
1362         struct ieee80211_conf *conf = &hw->conf;
1363
1364         mutex_lock(&priv->mutex);
1365
1366         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1367                 bool enable_radio = false;
1368                 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1369
1370                 mutex_lock(&priv->htc_pm_lock);
1371                 if (!idle && priv->ps_idle)
1372                         enable_radio = true;
1373                 priv->ps_idle = idle;
1374                 mutex_unlock(&priv->htc_pm_lock);
1375
1376                 if (enable_radio) {
1377                         ath_print(common, ATH_DBG_CONFIG,
1378                                   "not-idle: enabling radio\n");
1379                         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1380                         ath9k_htc_radio_enable(hw);
1381                 }
1382         }
1383
1384         if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1385                 struct ieee80211_channel *curchan = hw->conf.channel;
1386                 int pos = curchan->hw_value;
1387
1388                 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1389                           curchan->center_freq);
1390
1391                 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1392
1393                 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1394                         ath_print(common, ATH_DBG_FATAL,
1395                                   "Unable to set channel\n");
1396                         mutex_unlock(&priv->mutex);
1397                         return -EINVAL;
1398                 }
1399
1400         }
1401         if (changed & IEEE80211_CONF_CHANGE_PS) {
1402                 if (conf->flags & IEEE80211_CONF_PS) {
1403                         ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1404                         priv->ps_enabled = true;
1405                 } else {
1406                         priv->ps_enabled = false;
1407                         cancel_work_sync(&priv->ps_work);
1408                         ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1409                 }
1410         }
1411
1412         if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1413                 if (conf->flags & IEEE80211_CONF_MONITOR) {
1414                         if (ath9k_htc_add_monitor_interface(priv))
1415                                 ath_print(common, ATH_DBG_FATAL,
1416                                           "Failed to set monitor mode\n");
1417                         else
1418                                 ath_print(common, ATH_DBG_CONFIG,
1419                                           "HW opmode set to Monitor mode\n");
1420                 }
1421         }
1422
1423         if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1424                 mutex_lock(&priv->htc_pm_lock);
1425                 if (!priv->ps_idle) {
1426                         mutex_unlock(&priv->htc_pm_lock);
1427                         goto out;
1428                 }
1429                 mutex_unlock(&priv->htc_pm_lock);
1430
1431                 ath_print(common, ATH_DBG_CONFIG,
1432                           "idle: disabling radio\n");
1433                 ath9k_htc_radio_disable(hw);
1434         }
1435
1436 out:
1437         mutex_unlock(&priv->mutex);
1438         return 0;
1439 }
1440
1441 #define SUPPORTED_FILTERS                       \
1442         (FIF_PROMISC_IN_BSS |                   \
1443         FIF_ALLMULTI |                          \
1444         FIF_CONTROL |                           \
1445         FIF_PSPOLL |                            \
1446         FIF_OTHER_BSS |                         \
1447         FIF_BCN_PRBRESP_PROMISC |               \
1448         FIF_FCSFAIL)
1449
1450 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1451                                        unsigned int changed_flags,
1452                                        unsigned int *total_flags,
1453                                        u64 multicast)
1454 {
1455         struct ath9k_htc_priv *priv = hw->priv;
1456         u32 rfilt;
1457
1458         mutex_lock(&priv->mutex);
1459         ath9k_htc_ps_wakeup(priv);
1460
1461         changed_flags &= SUPPORTED_FILTERS;
1462         *total_flags &= SUPPORTED_FILTERS;
1463
1464         priv->rxfilter = *total_flags;
1465         rfilt = ath9k_htc_calcrxfilter(priv);
1466         ath9k_hw_setrxfilter(priv->ah, rfilt);
1467
1468         ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1469                   "Set HW RX filter: 0x%x\n", rfilt);
1470
1471         ath9k_htc_ps_restore(priv);
1472         mutex_unlock(&priv->mutex);
1473 }
1474
1475 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1476                              struct ieee80211_vif *vif,
1477                              struct ieee80211_sta *sta)
1478 {
1479         struct ath9k_htc_priv *priv = hw->priv;
1480         int ret;
1481
1482         mutex_lock(&priv->mutex);
1483         ath9k_htc_ps_wakeup(priv);
1484         ret = ath9k_htc_add_station(priv, vif, sta);
1485         if (!ret)
1486                 ath9k_htc_init_rate(priv, sta);
1487         ath9k_htc_ps_restore(priv);
1488         mutex_unlock(&priv->mutex);
1489
1490         return ret;
1491 }
1492
1493 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1494                                 struct ieee80211_vif *vif,
1495                                 struct ieee80211_sta *sta)
1496 {
1497         struct ath9k_htc_priv *priv = hw->priv;
1498         int ret;
1499
1500         mutex_lock(&priv->mutex);
1501         ath9k_htc_ps_wakeup(priv);
1502         ret = ath9k_htc_remove_station(priv, vif, sta);
1503         ath9k_htc_ps_restore(priv);
1504         mutex_unlock(&priv->mutex);
1505
1506         return ret;
1507 }
1508
1509 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1510                              const struct ieee80211_tx_queue_params *params)
1511 {
1512         struct ath9k_htc_priv *priv = hw->priv;
1513         struct ath_common *common = ath9k_hw_common(priv->ah);
1514         struct ath9k_tx_queue_info qi;
1515         int ret = 0, qnum;
1516
1517         if (queue >= WME_NUM_AC)
1518                 return 0;
1519
1520         mutex_lock(&priv->mutex);
1521         ath9k_htc_ps_wakeup(priv);
1522
1523         memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1524
1525         qi.tqi_aifs = params->aifs;
1526         qi.tqi_cwmin = params->cw_min;
1527         qi.tqi_cwmax = params->cw_max;
1528         qi.tqi_burstTime = params->txop;
1529
1530         qnum = get_hw_qnum(queue, priv->hwq_map);
1531
1532         ath_print(common, ATH_DBG_CONFIG,
1533                   "Configure tx [queue/hwq] [%d/%d],  "
1534                   "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1535                   queue, qnum, params->aifs, params->cw_min,
1536                   params->cw_max, params->txop);
1537
1538         ret = ath_htc_txq_update(priv, qnum, &qi);
1539         if (ret) {
1540                 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1541                 goto out;
1542         }
1543
1544         if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1545             (qnum == priv->hwq_map[WME_AC_BE]))
1546                     ath9k_htc_beaconq_config(priv);
1547 out:
1548         ath9k_htc_ps_restore(priv);
1549         mutex_unlock(&priv->mutex);
1550
1551         return ret;
1552 }
1553
1554 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1555                              enum set_key_cmd cmd,
1556                              struct ieee80211_vif *vif,
1557                              struct ieee80211_sta *sta,
1558                              struct ieee80211_key_conf *key)
1559 {
1560         struct ath9k_htc_priv *priv = hw->priv;
1561         struct ath_common *common = ath9k_hw_common(priv->ah);
1562         int ret = 0;
1563
1564         if (htc_modparam_nohwcrypt)
1565                 return -ENOSPC;
1566
1567         mutex_lock(&priv->mutex);
1568         ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1569         ath9k_htc_ps_wakeup(priv);
1570
1571         switch (cmd) {
1572         case SET_KEY:
1573                 ret = ath9k_cmn_key_config(common, vif, sta, key);
1574                 if (ret >= 0) {
1575                         key->hw_key_idx = ret;
1576                         /* push IV and Michael MIC generation to stack */
1577                         key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1578                         if (key->alg == ALG_TKIP)
1579                                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1580                         if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1581                                 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1582                         ret = 0;
1583                 }
1584                 break;
1585         case DISABLE_KEY:
1586                 ath9k_cmn_key_delete(common, key);
1587                 break;
1588         default:
1589                 ret = -EINVAL;
1590         }
1591
1592         ath9k_htc_ps_restore(priv);
1593         mutex_unlock(&priv->mutex);
1594
1595         return ret;
1596 }
1597
1598 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1599                                        struct ieee80211_vif *vif,
1600                                        struct ieee80211_bss_conf *bss_conf,
1601                                        u32 changed)
1602 {
1603         struct ath9k_htc_priv *priv = hw->priv;
1604         struct ath_hw *ah = priv->ah;
1605         struct ath_common *common = ath9k_hw_common(ah);
1606
1607         mutex_lock(&priv->mutex);
1608         ath9k_htc_ps_wakeup(priv);
1609
1610         if (changed & BSS_CHANGED_ASSOC) {
1611                 common->curaid = bss_conf->assoc ?
1612                                  bss_conf->aid : 0;
1613                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1614                         bss_conf->assoc);
1615
1616                 if (bss_conf->assoc) {
1617                         priv->op_flags |= OP_ASSOCIATED;
1618                         ath_start_ani(priv);
1619                 } else {
1620                         priv->op_flags &= ~OP_ASSOCIATED;
1621                         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1622                 }
1623         }
1624
1625         if (changed & BSS_CHANGED_BSSID) {
1626                 /* Set BSSID */
1627                 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1628                 ath9k_hw_write_associd(ah);
1629
1630                 ath_print(common, ATH_DBG_CONFIG,
1631                           "BSSID: %pM aid: 0x%x\n",
1632                           common->curbssid, common->curaid);
1633         }
1634
1635         if ((changed & BSS_CHANGED_BEACON_INT) ||
1636             (changed & BSS_CHANGED_BEACON) ||
1637             ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1638             bss_conf->enable_beacon)) {
1639                 priv->op_flags |= OP_ENABLE_BEACON;
1640                 ath9k_htc_beacon_config(priv, vif);
1641         }
1642
1643         if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1644             !bss_conf->enable_beacon) {
1645                 priv->op_flags &= ~OP_ENABLE_BEACON;
1646                 ath9k_htc_beacon_config(priv, vif);
1647         }
1648
1649         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1650                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1651                           bss_conf->use_short_preamble);
1652                 if (bss_conf->use_short_preamble)
1653                         priv->op_flags |= OP_PREAMBLE_SHORT;
1654                 else
1655                         priv->op_flags &= ~OP_PREAMBLE_SHORT;
1656         }
1657
1658         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1659                 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1660                           bss_conf->use_cts_prot);
1661                 if (bss_conf->use_cts_prot &&
1662                     hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1663                         priv->op_flags |= OP_PROTECT_ENABLE;
1664                 else
1665                         priv->op_flags &= ~OP_PROTECT_ENABLE;
1666         }
1667
1668         if (changed & BSS_CHANGED_ERP_SLOT) {
1669                 if (bss_conf->use_short_slot)
1670                         ah->slottime = 9;
1671                 else
1672                         ah->slottime = 20;
1673
1674                 ath9k_hw_init_global_settings(ah);
1675         }
1676
1677         if (changed & BSS_CHANGED_HT)
1678                 ath9k_htc_update_rate(priv, vif, bss_conf);
1679
1680         ath9k_htc_ps_restore(priv);
1681         mutex_unlock(&priv->mutex);
1682 }
1683
1684 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1685 {
1686         struct ath9k_htc_priv *priv = hw->priv;
1687         u64 tsf;
1688
1689         mutex_lock(&priv->mutex);
1690         ath9k_htc_ps_wakeup(priv);
1691         tsf = ath9k_hw_gettsf64(priv->ah);
1692         ath9k_htc_ps_restore(priv);
1693         mutex_unlock(&priv->mutex);
1694
1695         return tsf;
1696 }
1697
1698 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1699 {
1700         struct ath9k_htc_priv *priv = hw->priv;
1701
1702         mutex_lock(&priv->mutex);
1703         ath9k_htc_ps_wakeup(priv);
1704         ath9k_hw_settsf64(priv->ah, tsf);
1705         ath9k_htc_ps_restore(priv);
1706         mutex_unlock(&priv->mutex);
1707 }
1708
1709 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1710 {
1711         struct ath9k_htc_priv *priv = hw->priv;
1712
1713         mutex_lock(&priv->mutex);
1714         ath9k_htc_ps_wakeup(priv);
1715         ath9k_hw_reset_tsf(priv->ah);
1716         ath9k_htc_ps_restore(priv);
1717         mutex_unlock(&priv->mutex);
1718 }
1719
1720 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1721                                   struct ieee80211_vif *vif,
1722                                   enum ieee80211_ampdu_mlme_action action,
1723                                   struct ieee80211_sta *sta,
1724                                   u16 tid, u16 *ssn)
1725 {
1726         struct ath9k_htc_priv *priv = hw->priv;
1727         struct ath9k_htc_sta *ista;
1728         int ret = 0;
1729
1730         switch (action) {
1731         case IEEE80211_AMPDU_RX_START:
1732                 break;
1733         case IEEE80211_AMPDU_RX_STOP:
1734                 break;
1735         case IEEE80211_AMPDU_TX_START:
1736                 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1737                 if (!ret)
1738                         ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1739                 break;
1740         case IEEE80211_AMPDU_TX_STOP:
1741                 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1742                 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1743                 break;
1744         case IEEE80211_AMPDU_TX_OPERATIONAL:
1745                 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1746                 spin_lock_bh(&priv->tx_lock);
1747                 ista->tid_state[tid] = AGGR_OPERATIONAL;
1748                 spin_unlock_bh(&priv->tx_lock);
1749                 break;
1750         default:
1751                 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1752                           "Unknown AMPDU action\n");
1753         }
1754
1755         return ret;
1756 }
1757
1758 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1759 {
1760         struct ath9k_htc_priv *priv = hw->priv;
1761
1762         mutex_lock(&priv->mutex);
1763         spin_lock_bh(&priv->beacon_lock);
1764         priv->op_flags |= OP_SCANNING;
1765         spin_unlock_bh(&priv->beacon_lock);
1766         cancel_work_sync(&priv->ps_work);
1767         cancel_delayed_work_sync(&priv->ath9k_ani_work);
1768         mutex_unlock(&priv->mutex);
1769 }
1770
1771 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1772 {
1773         struct ath9k_htc_priv *priv = hw->priv;
1774
1775         mutex_lock(&priv->mutex);
1776         ath9k_htc_ps_wakeup(priv);
1777         spin_lock_bh(&priv->beacon_lock);
1778         priv->op_flags &= ~OP_SCANNING;
1779         spin_unlock_bh(&priv->beacon_lock);
1780         priv->op_flags |= OP_FULL_RESET;
1781         if (priv->op_flags & OP_ASSOCIATED)
1782                 ath9k_htc_beacon_config(priv, priv->vif);
1783         ath_start_ani(priv);
1784         ath9k_htc_ps_restore(priv);
1785         mutex_unlock(&priv->mutex);
1786 }
1787
1788 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1789 {
1790         return 0;
1791 }
1792
1793 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1794                                          u8 coverage_class)
1795 {
1796         struct ath9k_htc_priv *priv = hw->priv;
1797
1798         mutex_lock(&priv->mutex);
1799         ath9k_htc_ps_wakeup(priv);
1800         priv->ah->coverage_class = coverage_class;
1801         ath9k_hw_init_global_settings(priv->ah);
1802         ath9k_htc_ps_restore(priv);
1803         mutex_unlock(&priv->mutex);
1804 }
1805
1806 struct ieee80211_ops ath9k_htc_ops = {
1807         .tx                 = ath9k_htc_tx,
1808         .start              = ath9k_htc_start,
1809         .stop               = ath9k_htc_stop,
1810         .add_interface      = ath9k_htc_add_interface,
1811         .remove_interface   = ath9k_htc_remove_interface,
1812         .config             = ath9k_htc_config,
1813         .configure_filter   = ath9k_htc_configure_filter,
1814         .sta_add            = ath9k_htc_sta_add,
1815         .sta_remove         = ath9k_htc_sta_remove,
1816         .conf_tx            = ath9k_htc_conf_tx,
1817         .bss_info_changed   = ath9k_htc_bss_info_changed,
1818         .set_key            = ath9k_htc_set_key,
1819         .get_tsf            = ath9k_htc_get_tsf,
1820         .set_tsf            = ath9k_htc_set_tsf,
1821         .reset_tsf          = ath9k_htc_reset_tsf,
1822         .ampdu_action       = ath9k_htc_ampdu_action,
1823         .sw_scan_start      = ath9k_htc_sw_scan_start,
1824         .sw_scan_complete   = ath9k_htc_sw_scan_complete,
1825         .set_rts_threshold  = ath9k_htc_set_rts_threshold,
1826         .rfkill_poll        = ath9k_htc_rfkill_poll_state,
1827         .set_coverage_class = ath9k_htc_set_coverage_class,
1828 };