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