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