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