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