blob: 5f7e0bf4c986b5e38dbbd16bc3c3ff48fe4c5e47 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
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
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070017#include <linux/nl80211.h>
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080018#include <linux/delay.h>
Sujith394cf0a2009-02-09 13:26:54 +053019#include "ath9k.h"
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "btcoex.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021
Sujith Manoharan6dcc3442012-07-17 17:16:36 +053022static void ath9k_set_assoc_state(struct ath_softc *sc,
23 struct ieee80211_vif *vif);
24
Sven Eckelmann313eb872012-06-25 07:15:22 +020025u8 ath9k_parse_mpdudensity(u8 mpdudensity)
Sujithff37e332008-11-24 12:07:55 +053026{
27 /*
28 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
29 * 0 for no restriction
30 * 1 for 1/4 us
31 * 2 for 1/2 us
32 * 3 for 1 us
33 * 4 for 2 us
34 * 5 for 4 us
35 * 6 for 8 us
36 * 7 for 16 us
37 */
38 switch (mpdudensity) {
39 case 0:
40 return 0;
41 case 1:
42 case 2:
43 case 3:
44 /* Our lower layer calculations limit our precision to
45 1 microsecond */
46 return 1;
47 case 4:
48 return 2;
49 case 5:
50 return 4;
51 case 6:
52 return 8;
53 case 7:
54 return 16;
55 default:
56 return 0;
57 }
58}
59
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080060static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
61{
62 bool pending = false;
63
64 spin_lock_bh(&txq->axq_lock);
65
Felix Fietkau04535312014-06-11 16:17:51 +053066 if (txq->axq_depth)
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080067 pending = true;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080068
Felix Fietkau04535312014-06-11 16:17:51 +053069 if (txq->mac80211_qnum >= 0) {
70 struct list_head *list;
71
72 list = &sc->cur_chan->acq[txq->mac80211_qnum];
73 if (!list_empty(list))
74 pending = true;
75 }
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080076 spin_unlock_bh(&txq->axq_lock);
77 return pending;
78}
79
Mohammed Shafi Shajakhan6d79cb42011-05-19 17:40:46 +053080static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070081{
82 unsigned long flags;
83 bool ret;
84
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070085 spin_lock_irqsave(&sc->sc_pm_lock, flags);
86 ret = ath9k_hw_setpower(sc->sc_ah, mode);
87 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070088
89 return ret;
90}
91
Felix Fietkaubf3dac52013-11-11 22:23:33 +010092void ath_ps_full_sleep(unsigned long data)
93{
94 struct ath_softc *sc = (struct ath_softc *) data;
95 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
96 bool reset;
97
98 spin_lock(&common->cc_lock);
99 ath_hw_cycle_counters_update(common);
100 spin_unlock(&common->cc_lock);
101
102 ath9k_hw_setrxabort(sc->sc_ah, 1);
103 ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
104
105 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
106}
107
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700108void ath9k_ps_wakeup(struct ath_softc *sc)
109{
Felix Fietkau898c9142010-10-12 14:02:53 +0200110 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700111 unsigned long flags;
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100112 enum ath9k_power_mode power_mode;
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700113
114 spin_lock_irqsave(&sc->sc_pm_lock, flags);
115 if (++sc->ps_usecount != 1)
116 goto unlock;
117
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100118 del_timer_sync(&sc->sleep_timer);
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100119 power_mode = sc->sc_ah->power_mode;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700120 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700121
Felix Fietkau898c9142010-10-12 14:02:53 +0200122 /*
123 * While the hardware is asleep, the cycle counters contain no
124 * useful data. Better clear them now so that they don't mess up
125 * survey data results.
126 */
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100127 if (power_mode != ATH9K_PM_AWAKE) {
128 spin_lock(&common->cc_lock);
129 ath_hw_cycle_counters_update(common);
130 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
Rajkumar Manoharanc9ae6ab2012-06-04 16:28:41 +0530131 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100132 spin_unlock(&common->cc_lock);
133 }
Felix Fietkau898c9142010-10-12 14:02:53 +0200134
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700135 unlock:
136 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
137}
138
139void ath9k_ps_restore(struct ath_softc *sc)
140{
Felix Fietkau898c9142010-10-12 14:02:53 +0200141 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200142 enum ath9k_power_mode mode;
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700143 unsigned long flags;
144
145 spin_lock_irqsave(&sc->sc_pm_lock, flags);
146 if (--sc->ps_usecount != 0)
147 goto unlock;
148
Sujith Manoharanad128862012-04-24 10:23:20 +0530149 if (sc->ps_idle) {
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100150 mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
151 goto unlock;
152 }
153
154 if (sc->ps_enabled &&
Sujith Manoharanad128862012-04-24 10:23:20 +0530155 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
156 PS_WAIT_FOR_CAB |
157 PS_WAIT_FOR_PSPOLL_DATA |
Rajkumar Manoharan424749c2012-10-10 23:03:02 +0530158 PS_WAIT_FOR_TX_ACK |
159 PS_WAIT_FOR_ANI))) {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200160 mode = ATH9K_PM_NETWORK_SLEEP;
Rajkumar Manoharan08d4df42012-07-01 19:53:54 +0530161 if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
162 ath9k_btcoex_stop_gen_timer(sc);
Sujith Manoharanad128862012-04-24 10:23:20 +0530163 } else {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200164 goto unlock;
Sujith Manoharanad128862012-04-24 10:23:20 +0530165 }
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200166
167 spin_lock(&common->cc_lock);
168 ath_hw_cycle_counters_update(common);
169 spin_unlock(&common->cc_lock);
170
Felix Fietkau1a8f0d392011-09-22 08:04:32 -0600171 ath9k_hw_setpower(sc->sc_ah, mode);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700172
173 unlock:
174 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
175}
176
Felix Fietkau9adcf442011-09-03 01:40:26 +0200177static void __ath_cancel_work(struct ath_softc *sc)
178{
179 cancel_work_sync(&sc->paprd_work);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200180 cancel_delayed_work_sync(&sc->tx_complete_work);
181 cancel_delayed_work_sync(&sc->hw_pll_work);
Sujith Manoharanfad29cd2012-06-25 13:54:22 +0530182
Sujith Manoharanbf525922012-06-27 14:15:59 +0530183#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
Sujith Manoharanfad29cd2012-06-25 13:54:22 +0530184 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
185 cancel_work_sync(&sc->mci_work);
Sujith Manoharanbf525922012-06-27 14:15:59 +0530186#endif
Felix Fietkau9adcf442011-09-03 01:40:26 +0200187}
188
Sujith Manoharane60001e2013-10-28 12:22:04 +0530189void ath_cancel_work(struct ath_softc *sc)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200190{
191 __ath_cancel_work(sc);
192 cancel_work_sync(&sc->hw_reset_work);
193}
194
Sujith Manoharane60001e2013-10-28 12:22:04 +0530195void ath_restart_work(struct ath_softc *sc)
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530196{
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530197 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
198
Sujith Manoharan19c36162013-08-20 10:05:59 +0530199 if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530200 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
201 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
202
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530203 ath_start_ani(sc);
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530204}
205
John W. Linville9ebea382013-01-28 13:54:03 -0500206static bool ath_prepare_reset(struct ath_softc *sc)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200207{
208 struct ath_hw *ah = sc->sc_ah;
Felix Fietkauceea2a52012-05-24 14:32:19 +0200209 bool ret = true;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200210
211 ieee80211_stop_queues(sc->hw);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530212 ath_stop_ani(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200213 ath9k_hw_disable_interrupts(ah);
214
Felix Fietkau13815592013-01-20 18:51:53 +0100215 if (!ath_drain_all_txq(sc))
Felix Fietkau9adcf442011-09-03 01:40:26 +0200216 ret = false;
217
Felix Fietkau0a62acb2013-01-20 18:51:52 +0100218 if (!ath_stoprecv(sc))
Felix Fietkauceea2a52012-05-24 14:32:19 +0200219 ret = false;
220
Felix Fietkau9adcf442011-09-03 01:40:26 +0200221 return ret;
222}
223
224static bool ath_complete_reset(struct ath_softc *sc, bool start)
225{
226 struct ath_hw *ah = sc->sc_ah;
227 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan196fb862012-06-04 20:24:13 +0530228 unsigned long flags;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200229
230 if (ath_startrecv(sc) != 0) {
231 ath_err(common, "Unable to restart recv logic\n");
232 return false;
233 }
234
235 ath9k_cmn_update_txpow(ah, sc->curtxpow,
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530236 sc->cur_chan->txpower, &sc->curtxpow);
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530237
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100238 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
Felix Fietkau72d874c2011-10-08 20:06:19 +0200239 ath9k_hw_set_interrupts(ah);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200240 ath9k_hw_enable_interrupts(ah);
241
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530242 if (!sc->cur_chan->offchannel && start) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100243 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
Sujith Manoharan196fb862012-06-04 20:24:13 +0530244 goto work;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200245
Sujith Manoharan196fb862012-06-04 20:24:13 +0530246 if (ah->opmode == NL80211_IFTYPE_STATION &&
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100247 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
Sujith Manoharan196fb862012-06-04 20:24:13 +0530248 spin_lock_irqsave(&sc->sc_pm_lock, flags);
249 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
250 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Sujith Manoharana6768282013-05-06 10:09:03 +0530251 } else {
252 ath9k_set_beacon(sc);
Sujith Manoharan196fb862012-06-04 20:24:13 +0530253 }
254 work:
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530255 ath_restart_work(sc);
Felix Fietkau04535312014-06-11 16:17:51 +0530256 ath_txq_schedule_all(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200257 }
258
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530259 sc->gtt_cnt = 0;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200260 ieee80211_wake_queues(sc->hw);
261
Felix Fietkaud463af42014-04-06 00:37:03 +0200262 ath9k_p2p_ps_timer(sc);
263
Felix Fietkau9adcf442011-09-03 01:40:26 +0200264 return true;
265}
266
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530267int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200268{
269 struct ath_hw *ah = sc->sc_ah;
270 struct ath_common *common = ath9k_hw_common(ah);
271 struct ath9k_hw_cal_data *caldata = NULL;
272 bool fastcc = true;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200273 int r;
274
275 __ath_cancel_work(sc);
276
Felix Fietkau4668cce2013-01-14 16:56:46 +0100277 tasklet_disable(&sc->intr_tq);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200278 spin_lock_bh(&sc->sc_pcu_lock);
279
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530280 if (!sc->cur_chan->offchannel) {
Felix Fietkau9adcf442011-09-03 01:40:26 +0200281 fastcc = false;
282 caldata = &sc->caldata;
283 }
284
285 if (!hchan) {
286 fastcc = false;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200287 hchan = ah->curchan;
288 }
289
John W. Linville9ebea382013-01-28 13:54:03 -0500290 if (!ath_prepare_reset(sc))
Felix Fietkau9adcf442011-09-03 01:40:26 +0200291 fastcc = false;
292
Joe Perchesd2182b62011-12-15 14:55:53 -0800293 ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
Sujith Manoharanfeced202012-01-30 14:21:42 +0530294 hchan->channel, IS_CHAN_HT40(hchan), fastcc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200295
296 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
297 if (r) {
298 ath_err(common,
299 "Unable to reset channel, reset status %d\n", r);
Robert Shadef50b1cd2013-04-02 19:52:45 -0400300
301 ath9k_hw_enable_interrupts(ah);
302 ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
303
Felix Fietkau9adcf442011-09-03 01:40:26 +0200304 goto out;
305 }
306
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530307 if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530308 sc->cur_chan->offchannel)
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530309 ath9k_mci_set_txpower(sc, true, false);
310
Felix Fietkau9adcf442011-09-03 01:40:26 +0200311 if (!ath_complete_reset(sc, true))
312 r = -EIO;
313
314out:
315 spin_unlock_bh(&sc->sc_pcu_lock);
Felix Fietkau4668cce2013-01-14 16:56:46 +0100316 tasklet_enable(&sc->intr_tq);
317
Felix Fietkau9adcf442011-09-03 01:40:26 +0200318 return r;
319}
320
Ben Greear7e1e3862011-11-03 11:33:13 -0700321static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
322 struct ieee80211_vif *vif)
Sujithff37e332008-11-24 12:07:55 +0530323{
324 struct ath_node *an;
Sujithff37e332008-11-24 12:07:55 +0530325 an = (struct ath_node *)sta->drv_priv;
326
Sujith Manoharana145daf2012-11-28 15:08:54 +0530327 an->sc = sc;
Ben Greear7f010c92011-01-09 23:11:49 -0800328 an->sta = sta;
Ben Greear7e1e3862011-11-03 11:33:13 -0700329 an->vif = vif;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +0530330 memset(&an->key_idx, 0, sizeof(an->key_idx));
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530331
Sujith Manoharandd5ee592013-02-04 15:38:23 +0530332 ath_tx_node_init(sc, an);
Sujithff37e332008-11-24 12:07:55 +0530333}
334
335static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
336{
337 struct ath_node *an = (struct ath_node *)sta->drv_priv;
Sujith Manoharandd5ee592013-02-04 15:38:23 +0530338 ath_tx_node_cleanup(sc, an);
Sujithff37e332008-11-24 12:07:55 +0530339}
340
Sujith55624202010-01-08 10:36:02 +0530341void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530342{
343 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700344 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700345 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530346 enum ath_reset_type type;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530347 unsigned long flags;
Sujith17d79042009-02-09 13:27:03 +0530348 u32 status = sc->intrstatus;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400349 u32 rxmask;
Sujithff37e332008-11-24 12:07:55 +0530350
Felix Fietkaue3927002011-09-14 21:23:01 +0200351 ath9k_ps_wakeup(sc);
352 spin_lock(&sc->sc_pcu_lock);
353
Sujith Manoharan6549a862013-12-24 10:44:24 +0530354 if (status & ATH9K_INT_FATAL) {
355 type = RESET_TYPE_FATAL_INT;
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530356 ath9k_queue_reset(sc, type);
Sujith Manoharanc6cc47b2013-09-16 10:37:00 +0530357
358 /*
359 * Increment the ref. counter here so that
360 * interrupts are enabled in the reset routine.
361 */
362 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100363 ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
Felix Fietkaue3927002011-09-14 21:23:01 +0200364 goto out;
Sujithff37e332008-11-24 12:07:55 +0530365 }
366
Sujith Manoharan6549a862013-12-24 10:44:24 +0530367 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
368 (status & ATH9K_INT_BB_WATCHDOG)) {
Sujith Manoharan0c759972013-12-24 10:44:26 +0530369 spin_lock(&common->cc_lock);
370 ath_hw_cycle_counters_update(common);
371 ar9003_hw_bb_watchdog_dbg_info(ah);
372 spin_unlock(&common->cc_lock);
373
Sujith Manoharan6549a862013-12-24 10:44:24 +0530374 if (ar9003_hw_bb_watchdog_check(ah)) {
375 type = RESET_TYPE_BB_WATCHDOG;
376 ath9k_queue_reset(sc, type);
377
378 /*
379 * Increment the ref. counter here so that
380 * interrupts are enabled in the reset routine.
381 */
382 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100383 ath_dbg(common, RESET,
Sujith Manoharan6549a862013-12-24 10:44:24 +0530384 "BB_WATCHDOG: Skipping interrupts\n");
385 goto out;
386 }
387 }
388
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530389 if (status & ATH9K_INT_GTT) {
390 sc->gtt_cnt++;
391
392 if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
393 type = RESET_TYPE_TX_GTT;
394 ath9k_queue_reset(sc, type);
395 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100396 ath_dbg(common, RESET,
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530397 "GTT: Skipping interrupts\n");
398 goto out;
399 }
400 }
401
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530402 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530403 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
404 /*
405 * TSF sync does not look correct; remain awake to sync with
406 * the next Beacon.
407 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800408 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
Rajkumar Manoharane8fe7332011-08-05 18:59:41 +0530409 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530410 }
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530411 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530412
Felix Fietkaub5c804752010-04-15 17:38:48 -0400413 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
414 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
415 ATH9K_INT_RXORN);
416 else
417 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
418
419 if (status & rxmask) {
Felix Fietkaub5c804752010-04-15 17:38:48 -0400420 /* Check for high priority Rx first */
421 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
422 (status & ATH9K_INT_RXHP))
423 ath_rx_tasklet(sc, 0, true);
424
425 ath_rx_tasklet(sc, 0, false);
Sujith063d8be2009-03-30 15:28:49 +0530426 }
427
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400428 if (status & ATH9K_INT_TX) {
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530429 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
430 /*
431 * For EDMA chips, TX completion is enabled for the
432 * beacon queue, so if a beacon has been transmitted
433 * successfully after a GTT interrupt, the GTT counter
434 * gets reset to zero here.
435 */
Sujith Manoharan3b745c72014-01-20 13:25:28 +0530436 sc->gtt_cnt = 0;
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530437
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400438 ath_tx_edma_tasklet(sc);
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530439 } else {
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400440 ath_tx_tasklet(sc);
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530441 }
Felix Fietkau10e23182013-11-11 22:23:35 +0100442
443 wake_up(&sc->tx_wait);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400444 }
Sujith063d8be2009-03-30 15:28:49 +0530445
Felix Fietkauc67ce332013-12-14 18:03:38 +0100446 if (status & ATH9K_INT_GENTIMER)
447 ath_gen_timer_isr(sc->sc_ah);
448
Sujith Manoharan56ca0db2012-02-22 12:40:32 +0530449 ath9k_btcoex_handle_interrupt(sc, status);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530450
Sujithff37e332008-11-24 12:07:55 +0530451 /* re-enable hardware interrupt */
Felix Fietkau4df30712010-11-08 20:54:47 +0100452 ath9k_hw_enable_interrupts(ah);
Sujith Manoharanc6cc47b2013-09-16 10:37:00 +0530453out:
Senthil Balasubramanian52671e42010-12-23 21:06:57 +0530454 spin_unlock(&sc->sc_pcu_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400455 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530456}
457
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100458irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530459{
Sujith063d8be2009-03-30 15:28:49 +0530460#define SCHED_INTR ( \
461 ATH9K_INT_FATAL | \
Rajkumar Manoharana4d86d92011-05-20 17:52:10 +0530462 ATH9K_INT_BB_WATCHDOG | \
Sujith063d8be2009-03-30 15:28:49 +0530463 ATH9K_INT_RXORN | \
464 ATH9K_INT_RXEOL | \
465 ATH9K_INT_RX | \
Felix Fietkaub5c804752010-04-15 17:38:48 -0400466 ATH9K_INT_RXLP | \
467 ATH9K_INT_RXHP | \
Sujith063d8be2009-03-30 15:28:49 +0530468 ATH9K_INT_TX | \
469 ATH9K_INT_BMISS | \
470 ATH9K_INT_CST | \
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530471 ATH9K_INT_GTT | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530472 ATH9K_INT_TSFOOR | \
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530473 ATH9K_INT_GENTIMER | \
474 ATH9K_INT_MCI)
Sujith063d8be2009-03-30 15:28:49 +0530475
Sujithff37e332008-11-24 12:07:55 +0530476 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530477 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100478 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530479 enum ath9k_int status;
Sujith Manoharan78c8a952013-12-28 09:47:15 +0530480 u32 sync_cause = 0;
Sujithff37e332008-11-24 12:07:55 +0530481 bool sched = false;
482
Sujith063d8be2009-03-30 15:28:49 +0530483 /*
484 * The hardware is not ready/present, don't
485 * touch anything. Note this can happen early
486 * on if the IRQ is shared.
487 */
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100488 if (test_bit(ATH_OP_INVALID, &common->op_flags))
Sujith063d8be2009-03-30 15:28:49 +0530489 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530490
Sujith063d8be2009-03-30 15:28:49 +0530491 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530492
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400493 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530494 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530495
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100496 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
Felix Fietkauf41a9b32012-08-08 16:25:03 +0200497 ath9k_hw_kill_interrupts(ah);
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530498 return IRQ_HANDLED;
Felix Fietkauf41a9b32012-08-08 16:25:03 +0200499 }
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530500
Sujith063d8be2009-03-30 15:28:49 +0530501 /*
502 * Figure out the reason(s) for the interrupt. Note
503 * that the hal returns a pseudo-ISR that may include
504 * bits we haven't explicitly enabled so we mask the
505 * value to insure we only process bits we requested.
506 */
Felix Fietkau6a4d05d2013-12-19 18:01:48 +0100507 ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
508 ath9k_debug_sync_cause(sc, sync_cause);
Pavel Roskin30691682010-03-31 18:05:31 -0400509 status &= ah->imask; /* discard unasked-for bits */
Sujith063d8be2009-03-30 15:28:49 +0530510
511 /*
512 * If there are no status bits set, then this interrupt was not
513 * for me (should have been caught above).
514 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400515 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530516 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530517
518 /* Cache the status */
519 sc->intrstatus = status;
520
521 if (status & SCHED_INTR)
522 sched = true;
523
524 /*
525 * If a FATAL or RXORN interrupt is received, we have to reset the
526 * chip immediately.
527 */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400528 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
529 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
Sujith063d8be2009-03-30 15:28:49 +0530530 goto chip_reset;
531
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530532 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
Sujith Manoharan0c759972013-12-24 10:44:26 +0530533 (status & ATH9K_INT_BB_WATCHDOG))
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400534 goto chip_reset;
Sujith Manoharane60001e2013-10-28 12:22:04 +0530535
536#ifdef CONFIG_ATH9K_WOW
Rajkumar Manoharanca90ef42012-11-20 18:29:59 +0530537 if (status & ATH9K_INT_BMISS) {
538 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
Rajkumar Manoharanca90ef42012-11-20 18:29:59 +0530539 atomic_inc(&sc->wow_got_bmiss_intr);
540 atomic_dec(&sc->wow_sleep_proc_intr);
541 }
542 }
543#endif
Sujith Manoharane60001e2013-10-28 12:22:04 +0530544
Sujith063d8be2009-03-30 15:28:49 +0530545 if (status & ATH9K_INT_SWBA)
546 tasklet_schedule(&sc->bcon_tasklet);
547
548 if (status & ATH9K_INT_TXURN)
549 ath9k_hw_updatetxtriglevel(ah, true);
550
Rajkumar Manoharan0682c9b2011-08-13 10:28:09 +0530551 if (status & ATH9K_INT_RXEOL) {
552 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +0200553 ath9k_hw_set_interrupts(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400554 }
555
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400556 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
557 if (status & ATH9K_INT_TIM_TIMER) {
Luis R. Rodriguezff9f0b62010-12-07 15:13:22 -0800558 if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
559 goto chip_reset;
Sujith063d8be2009-03-30 15:28:49 +0530560 /* Clear RxAbort bit so that we can
561 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700562 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530563 spin_lock(&sc->sc_pm_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400564 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530565 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530566 spin_unlock(&sc->sc_pm_lock);
Sujith063d8be2009-03-30 15:28:49 +0530567 }
Sujith063d8be2009-03-30 15:28:49 +0530568
569chip_reset:
570
Sujith817e11d2008-12-07 21:42:44 +0530571 ath_debug_stat_interrupt(sc, status);
572
Sujithff37e332008-11-24 12:07:55 +0530573 if (sched) {
Felix Fietkau4df30712010-11-08 20:54:47 +0100574 /* turn off every interrupt */
575 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530576 tasklet_schedule(&sc->intr_tq);
577 }
578
579 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530580
581#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530582}
583
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530584int ath_reset(struct ath_softc *sc)
Sujithff37e332008-11-24 12:07:55 +0530585{
Felix Fietkauec303262013-10-05 14:09:30 +0200586 int r;
Sujithff37e332008-11-24 12:07:55 +0530587
Felix Fietkau783cd012011-01-21 18:52:38 +0100588 ath9k_ps_wakeup(sc);
Felix Fietkau13815592013-01-20 18:51:53 +0100589 r = ath_reset_internal(sc, NULL);
Felix Fietkau783cd012011-01-21 18:52:38 +0100590 ath9k_ps_restore(sc);
Sujith2ab81d42009-12-14 16:34:56 +0530591
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800592 return r;
Sujithff37e332008-11-24 12:07:55 +0530593}
594
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530595void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
596{
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100597 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530598#ifdef CONFIG_ATH9K_DEBUGFS
599 RESET_STAT_INC(sc, type);
600#endif
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100601 set_bit(ATH_OP_HW_RESET, &common->op_flags);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530602 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
603}
604
Felix Fietkau236de512011-09-03 01:40:25 +0200605void ath_reset_work(struct work_struct *work)
606{
607 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
608
Felix Fietkau13815592013-01-20 18:51:53 +0100609 ath_reset(sc);
Felix Fietkau236de512011-09-03 01:40:25 +0200610}
611
Sujithff37e332008-11-24 12:07:55 +0530612/**********************/
613/* mac80211 callbacks */
614/**********************/
615
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616static int ath9k_start(struct ieee80211_hw *hw)
617{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100618 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700619 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700620 struct ath_common *common = ath9k_hw_common(ah);
Karl Beldan675a0b02013-03-25 16:26:57 +0100621 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530622 struct ath_chanctx *ctx = sc->cur_chan;
Sujithff37e332008-11-24 12:07:55 +0530623 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530624 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700625
Joe Perchesd2182b62011-12-15 14:55:53 -0800626 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -0800627 "Starting driver with initial channel: %d MHz\n",
628 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629
Felix Fietkauf62d8162011-03-25 17:43:41 +0100630 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +0530631 mutex_lock(&sc->mutex);
632
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530633 memcpy(&ctx->chandef, &hw->conf.chandef, sizeof(ctx->chandef));
634 init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700635
Sujithff37e332008-11-24 12:07:55 +0530636 /* Reset SERDES registers */
Stanislaw Gruszka84c87dc2011-08-05 13:10:32 +0200637 ath9k_hw_configpcipowersave(ah, false);
Sujithff37e332008-11-24 12:07:55 +0530638
639 /*
640 * The basic interface to setting the hardware in a good
641 * state is ``reset''. On return the hardware is known to
642 * be powered up and with interrupts disabled. This must
643 * be followed by initialization of the appropriate bits
644 * and then setup of the interrupt mask.
645 */
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700646 spin_lock_bh(&sc->sc_pcu_lock);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100647
648 atomic_set(&ah->intr_ref_cnt, -1);
649
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200650 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800651 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800652 ath_err(common,
653 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
654 r, curchan->center_freq);
Felix Fietkauceb26a62012-10-03 21:07:51 +0200655 ah->reset_power_on = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700656 }
Sujithff37e332008-11-24 12:07:55 +0530657
Sujithff37e332008-11-24 12:07:55 +0530658 /* Setup our intr mask. */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400659 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
660 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
661 ATH9K_INT_GLOBAL;
662
663 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400664 ah->imask |= ATH9K_INT_RXHP |
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530665 ATH9K_INT_RXLP;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400666 else
667 ah->imask |= ATH9K_INT_RX;
Sujithff37e332008-11-24 12:07:55 +0530668
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530669 if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
670 ah->imask |= ATH9K_INT_BB_WATCHDOG;
671
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530672 /*
673 * Enable GTT interrupts only for AR9003/AR9004 chips
674 * for now.
675 */
676 if (AR_SREV_9300_20_OR_LATER(ah))
677 ah->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +0530678
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700679 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Pavel Roskin30691682010-03-31 18:05:31 -0400680 ah->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +0530681
Sujith Manoharane270e772012-06-04 16:27:19 +0530682 ath_mci_enable(sc);
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530683
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100684 clear_bit(ATH_OP_INVALID, &common->op_flags);
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530685 sc->sc_ah->is_monitoring = false;
Sujithff37e332008-11-24 12:07:55 +0530686
Felix Fietkauceb26a62012-10-03 21:07:51 +0200687 if (!ath_complete_reset(sc, false))
688 ah->reset_power_on = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700689
Felix Fietkauc0c11742011-11-16 13:08:41 +0100690 if (ah->led_pin >= 0) {
691 ath9k_hw_cfg_output(ah, ah->led_pin,
692 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
693 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
694 }
695
696 /*
697 * Reset key cache to sane defaults (all entries cleared) instead of
698 * semi-random values after suspend/resume.
699 */
700 ath9k_cmn_init_crypto(sc->sc_ah);
701
Felix Fietkaua35051c2013-12-14 18:03:45 +0100702 ath9k_hw_reset_tsf(ah);
703
Felix Fietkau9adcf442011-09-03 01:40:26 +0200704 spin_unlock_bh(&sc->sc_pcu_lock);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -0400705
Sujith141b38b2009-02-04 08:10:07 +0530706 mutex_unlock(&sc->mutex);
707
Felix Fietkauf62d8162011-03-25 17:43:41 +0100708 ath9k_ps_restore(sc);
709
Felix Fietkauceb26a62012-10-03 21:07:51 +0200710 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711}
712
Thomas Huehn36323f82012-07-23 21:33:42 +0200713static void ath9k_tx(struct ieee80211_hw *hw,
714 struct ieee80211_tx_control *control,
715 struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700716{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100717 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700718 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +0530719 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +0100720 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530721 unsigned long flags;
Sujith528f0c62008-10-29 10:14:26 +0530722
Gabor Juhos96148322009-07-24 17:27:21 +0200723 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +0300724 /*
725 * mac80211 does not set PM field for normal data frames, so we
726 * need to update that based on the current PS mode.
727 */
728 if (ieee80211_is_data(hdr->frame_control) &&
729 !ieee80211_is_nullfunc(hdr->frame_control) &&
730 !ieee80211_has_pm(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800731 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800732 "Add PM=1 for a TX frame while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +0300733 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
734 }
735 }
736
Sujith Manoharanad128862012-04-24 10:23:20 +0530737 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300738 /*
739 * We are using PS-Poll and mac80211 can request TX while in
740 * power save mode. Need to wake up hardware for the TX to be
741 * completed and if needed, also for RX of buffered frames.
742 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300743 ath9k_ps_wakeup(sc);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530744 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -0700745 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
746 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300747 if (ieee80211_is_pspoll(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800748 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800749 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +0530750 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300751 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -0800752 ath_dbg(common, PS, "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +0530753 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300754 }
755 /*
756 * The actual restore operation will happen only after
Sujith Manoharanad128862012-04-24 10:23:20 +0530757 * the ps_flags bit is cleared. We are just dropping
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300758 * the ps_usecount here.
759 */
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530760 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300761 ath9k_ps_restore(sc);
762 }
763
Sujith Manoharanad128862012-04-24 10:23:20 +0530764 /*
765 * Cannot tx while the hardware is in full sleep, it first needs a full
766 * chip reset to recover from that
767 */
768 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
769 ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
770 goto exit;
771 }
772
Sujith528f0c62008-10-29 10:14:26 +0530773 memset(&txctl, 0, sizeof(struct ath_tx_control));
Felix Fietkau066dae92010-11-07 14:59:39 +0100774 txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
Thomas Huehn36323f82012-07-23 21:33:42 +0200775 txctl.sta = control->sta;
Sujith528f0c62008-10-29 10:14:26 +0530776
Joe Perchesd2182b62011-12-15 14:55:53 -0800777 ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200779 if (ath_tx_start(hw, skb, &txctl) != 0) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800780 ath_dbg(common, XMIT, "TX failed\n");
Ben Greeara5a0bca2012-04-03 09:16:55 -0700781 TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
Sujith528f0c62008-10-29 10:14:26 +0530782 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700783 }
784
Johannes Berg7bb45682011-02-24 14:42:06 +0100785 return;
Sujith528f0c62008-10-29 10:14:26 +0530786exit:
Felix Fietkau249ee722012-10-03 21:07:52 +0200787 ieee80211_free_txskb(hw, skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700788}
789
790static void ath9k_stop(struct ieee80211_hw *hw)
791{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100792 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700793 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700794 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100795 bool prev_idle;
Sujith9c84b792008-10-29 10:17:13 +0530796
Sujith4c483812009-08-18 10:51:52 +0530797 mutex_lock(&sc->mutex);
798
Felix Fietkau9adcf442011-09-03 01:40:26 +0200799 ath_cancel_work(sc);
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -0700800
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100801 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800802 ath_dbg(common, ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +0530803 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +0530804 return;
805 }
806
Sujith3867cf62009-12-23 20:03:27 -0500807 /* Ensure HW is awake when we try to shut it down. */
808 ath9k_ps_wakeup(sc);
809
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700810 spin_lock_bh(&sc->sc_pcu_lock);
811
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100812 /* prevent tasklets to enable interrupts once we disable them */
813 ah->imask &= ~ATH9K_INT_GLOBAL;
814
Sujithff37e332008-11-24 12:07:55 +0530815 /* make sure h/w will not generate any interrupt
816 * before setting the invalid flag. */
Felix Fietkau4df30712010-11-08 20:54:47 +0100817 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530818
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700819 spin_unlock_bh(&sc->sc_pcu_lock);
820
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100821 /* we can now sync irq and kill any running tasklets, since we already
822 * disabled interrupts and not holding a spin lock */
823 synchronize_irq(sc->irq);
824 tasklet_kill(&sc->intr_tq);
825 tasklet_kill(&sc->bcon_tasklet);
826
Felix Fietkauc0c11742011-11-16 13:08:41 +0100827 prev_idle = sc->ps_idle;
828 sc->ps_idle = true;
829
830 spin_lock_bh(&sc->sc_pcu_lock);
831
832 if (ah->led_pin >= 0) {
833 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
834 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
835 }
836
John W. Linville9ebea382013-01-28 13:54:03 -0500837 ath_prepare_reset(sc);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100838
839 if (sc->rx.frag) {
840 dev_kfree_skb_any(sc->rx.frag);
841 sc->rx.frag = NULL;
842 }
843
844 if (!ah->curchan)
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530845 ah->curchan = ath9k_cmn_get_channel(hw, ah,
846 &sc->cur_chan->chandef);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100847
848 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
849 ath9k_hw_phy_disable(ah);
850
851 ath9k_hw_configpcipowersave(ah, true);
852
853 spin_unlock_bh(&sc->sc_pcu_lock);
854
Sujith3867cf62009-12-23 20:03:27 -0500855 ath9k_ps_restore(sc);
856
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100857 set_bit(ATH_OP_INVALID, &common->op_flags);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100858 sc->ps_idle = prev_idle;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700859
Sujith141b38b2009-02-04 08:10:07 +0530860 mutex_unlock(&sc->mutex);
861
Joe Perchesd2182b62011-12-15 14:55:53 -0800862 ath_dbg(common, CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700863}
864
Felix Fietkauc648ecb2013-10-11 23:31:00 +0200865static bool ath9k_uses_beacons(int type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700866{
Ben Greear48014162011-01-15 19:13:48 +0000867 switch (type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200868 case NL80211_IFTYPE_AP:
Ben Greear48014162011-01-15 19:13:48 +0000869 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -0400870 case NL80211_IFTYPE_MESH_POINT:
Ben Greear48014162011-01-15 19:13:48 +0000871 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872 default:
Ben Greear48014162011-01-15 19:13:48 +0000873 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700874 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700875}
876
Ben Greear48014162011-01-15 19:13:48 +0000877static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
878{
879 struct ath9k_vif_iter_data *iter_data = data;
880 int i;
881
Felix Fietkauab11bb22013-04-16 12:51:57 +0200882 if (iter_data->has_hw_macaddr) {
Ben Greear48014162011-01-15 19:13:48 +0000883 for (i = 0; i < ETH_ALEN; i++)
884 iter_data->mask[i] &=
885 ~(iter_data->hw_macaddr[i] ^ mac[i]);
Felix Fietkauab11bb22013-04-16 12:51:57 +0200886 } else {
887 memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
888 iter_data->has_hw_macaddr = true;
889 }
Ben Greear48014162011-01-15 19:13:48 +0000890
891 switch (vif->type) {
892 case NL80211_IFTYPE_AP:
893 iter_data->naps++;
894 break;
895 case NL80211_IFTYPE_STATION:
896 iter_data->nstations++;
897 break;
898 case NL80211_IFTYPE_ADHOC:
899 iter_data->nadhocs++;
900 break;
901 case NL80211_IFTYPE_MESH_POINT:
902 iter_data->nmeshes++;
903 break;
904 case NL80211_IFTYPE_WDS:
905 iter_data->nwds++;
906 break;
907 default:
Ben Greear48014162011-01-15 19:13:48 +0000908 break;
909 }
910}
911
Sujith Manoharan6dcc3442012-07-17 17:16:36 +0530912static void ath9k_sta_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
913{
914 struct ath_softc *sc = data;
915 struct ath_vif *avp = (void *)vif->drv_priv;
916
917 if (vif->type != NL80211_IFTYPE_STATION)
918 return;
919
920 if (avp->primary_sta_vif)
921 ath9k_set_assoc_state(sc, vif);
922}
923
Ben Greear48014162011-01-15 19:13:48 +0000924/* Called with sc->mutex held. */
925void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
926 struct ieee80211_vif *vif,
927 struct ath9k_vif_iter_data *iter_data)
928{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100929 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000930 struct ath_hw *ah = sc->sc_ah;
931 struct ath_common *common = ath9k_hw_common(ah);
Ben Greear48014162011-01-15 19:13:48 +0000932
933 /*
Mathy Vanhoef657eb172013-11-28 12:21:45 +0100934 * Pick the MAC address of the first interface as the new hardware
935 * MAC address. The hardware will use it together with the BSSID mask
936 * when matching addresses.
Ben Greear48014162011-01-15 19:13:48 +0000937 */
938 memset(iter_data, 0, sizeof(*iter_data));
Ben Greear48014162011-01-15 19:13:48 +0000939 memset(&iter_data->mask, 0xff, ETH_ALEN);
940
941 if (vif)
942 ath9k_vif_iter(iter_data, vif->addr, vif);
943
944 /* Get list of all active MAC addresses */
Johannes Berg8b2c9822012-11-06 20:23:30 +0100945 ieee80211_iterate_active_interfaces_atomic(
946 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
947 ath9k_vif_iter, iter_data);
Felix Fietkauab11bb22013-04-16 12:51:57 +0200948
949 memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
Ben Greear48014162011-01-15 19:13:48 +0000950}
951
952/* Called with sc->mutex held. */
953static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
954 struct ieee80211_vif *vif)
955{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100956 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000957 struct ath_hw *ah = sc->sc_ah;
958 struct ath_common *common = ath9k_hw_common(ah);
959 struct ath9k_vif_iter_data iter_data;
Sujith Manoharan6dcc3442012-07-17 17:16:36 +0530960 enum nl80211_iftype old_opmode = ah->opmode;
Ben Greear48014162011-01-15 19:13:48 +0000961
962 ath9k_calculate_iter_data(hw, vif, &iter_data);
963
Ben Greear48014162011-01-15 19:13:48 +0000964 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
965 ath_hw_setbssidmask(common);
966
Ben Greear48014162011-01-15 19:13:48 +0000967 if (iter_data.naps > 0) {
Sujith Manoharan60ca9f82012-07-17 17:15:37 +0530968 ath9k_hw_set_tsfadjust(ah, true);
Ben Greear48014162011-01-15 19:13:48 +0000969 ah->opmode = NL80211_IFTYPE_AP;
970 } else {
Sujith Manoharan60ca9f82012-07-17 17:15:37 +0530971 ath9k_hw_set_tsfadjust(ah, false);
Ben Greear48014162011-01-15 19:13:48 +0000972
Javier Cardonafd5999c2011-05-03 16:57:19 -0700973 if (iter_data.nmeshes)
974 ah->opmode = NL80211_IFTYPE_MESH_POINT;
975 else if (iter_data.nwds)
Ben Greear48014162011-01-15 19:13:48 +0000976 ah->opmode = NL80211_IFTYPE_AP;
977 else if (iter_data.nadhocs)
978 ah->opmode = NL80211_IFTYPE_ADHOC;
979 else
980 ah->opmode = NL80211_IFTYPE_STATION;
981 }
982
Sujith Manoharandf35d292012-07-17 17:15:43 +0530983 ath9k_hw_setopmode(ah);
984
Felix Fietkau198823f2012-06-15 15:25:25 +0200985 if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
Ben Greear48014162011-01-15 19:13:48 +0000986 ah->imask |= ATH9K_INT_TSFOOR;
Felix Fietkau198823f2012-06-15 15:25:25 +0200987 else
Ben Greear48014162011-01-15 19:13:48 +0000988 ah->imask &= ~ATH9K_INT_TSFOOR;
Ben Greear48014162011-01-15 19:13:48 +0000989
Felix Fietkau72d874c2011-10-08 20:06:19 +0200990 ath9k_hw_set_interrupts(ah);
Sujith Manoharan6dcc3442012-07-17 17:16:36 +0530991
992 /*
993 * If we are changing the opmode to STATION,
994 * a beacon sync needs to be done.
995 */
996 if (ah->opmode == NL80211_IFTYPE_STATION &&
997 old_opmode == NL80211_IFTYPE_AP &&
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100998 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
Johannes Berg8b2c9822012-11-06 20:23:30 +0100999 ieee80211_iterate_active_interfaces_atomic(
1000 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1001 ath9k_sta_vif_iter, sc);
Sujith Manoharan6dcc3442012-07-17 17:16:36 +05301002 }
Ben Greear48014162011-01-15 19:13:48 +00001003}
1004
Ben Greear48014162011-01-15 19:13:48 +00001005static int ath9k_add_interface(struct ieee80211_hw *hw,
1006 struct ieee80211_vif *vif)
1007{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001008 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +00001009 struct ath_hw *ah = sc->sc_ah;
1010 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001011 struct ath_vif *avp = (void *)vif->drv_priv;
1012 struct ath_node *an = &avp->mcast_node;
Ben Greear48014162011-01-15 19:13:48 +00001013
1014 mutex_lock(&sc->mutex);
1015
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001016 if (config_enabled(CONFIG_ATH9K_TX99)) {
1017 if (sc->nvifs >= 1) {
1018 mutex_unlock(&sc->mutex);
1019 return -EOPNOTSUPP;
1020 }
1021 sc->tx99_vif = vif;
1022 }
1023
Joe Perchesd2182b62011-12-15 14:55:53 -08001024 ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
Ben Greear48014162011-01-15 19:13:48 +00001025 sc->nvifs++;
1026
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301027 ath9k_ps_wakeup(sc);
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301028 ath9k_calculate_summary_state(hw, vif);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301029 ath9k_ps_restore(sc);
1030
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301031 if (ath9k_uses_beacons(vif->type))
1032 ath9k_beacon_assign_slot(sc, vif);
1033
Felix Fietkaud463af42014-04-06 00:37:03 +02001034 avp->vif = vif;
1035
Felix Fietkau04535312014-06-11 16:17:51 +05301036 /* XXX - will be removed once chanctx ops are added */
1037 avp->chanctx = sc->cur_chan;
1038 list_add_tail(&avp->list, &sc->cur_chan->vifs);
1039
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001040 an->sc = sc;
1041 an->sta = NULL;
1042 an->vif = vif;
1043 an->no_ps_filter = true;
1044 ath_tx_node_init(sc, an);
1045
Ben Greear48014162011-01-15 19:13:48 +00001046 mutex_unlock(&sc->mutex);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301047 return 0;
Ben Greear48014162011-01-15 19:13:48 +00001048}
1049
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301050static int ath9k_change_interface(struct ieee80211_hw *hw,
1051 struct ieee80211_vif *vif,
1052 enum nl80211_iftype new_type,
1053 bool p2p)
1054{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001055 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301056 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1057
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301058 mutex_lock(&sc->mutex);
Ben Greear48014162011-01-15 19:13:48 +00001059
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001060 if (config_enabled(CONFIG_ATH9K_TX99)) {
1061 mutex_unlock(&sc->mutex);
1062 return -EOPNOTSUPP;
1063 }
1064
1065 ath_dbg(common, CONFIG, "Change Interface\n");
1066
Ben Greear48014162011-01-15 19:13:48 +00001067 if (ath9k_uses_beacons(vif->type))
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301068 ath9k_beacon_remove_slot(sc, vif);
Ben Greear48014162011-01-15 19:13:48 +00001069
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301070 vif->type = new_type;
1071 vif->p2p = p2p;
1072
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301073 ath9k_ps_wakeup(sc);
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301074 ath9k_calculate_summary_state(hw, vif);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301075 ath9k_ps_restore(sc);
1076
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301077 if (ath9k_uses_beacons(vif->type))
1078 ath9k_beacon_assign_slot(sc, vif);
1079
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301080 mutex_unlock(&sc->mutex);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301081 return 0;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301082}
1083
Felix Fietkaud463af42014-04-06 00:37:03 +02001084static void
1085ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
1086{
1087 struct ath_hw *ah = sc->sc_ah;
1088 s32 tsf, target_tsf;
1089
1090 if (!avp || !avp->noa.has_next_tsf)
1091 return;
1092
1093 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
1094
1095 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1096
1097 target_tsf = avp->noa.next_tsf;
1098 if (!avp->noa.absent)
1099 target_tsf -= ATH_P2P_PS_STOP_TIME;
1100
1101 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
1102 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
1103
1104 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
1105}
1106
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001107static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001108 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001109{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001110 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001111 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001112 struct ath_vif *avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001113
Joe Perchesd2182b62011-12-15 14:55:53 -08001114 ath_dbg(common, CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001115
Sujith141b38b2009-02-04 08:10:07 +05301116 mutex_lock(&sc->mutex);
1117
Felix Fietkaud463af42014-04-06 00:37:03 +02001118 spin_lock_bh(&sc->sc_pcu_lock);
1119 if (avp == sc->p2p_ps_vif) {
1120 sc->p2p_ps_vif = NULL;
1121 ath9k_update_p2p_ps_timer(sc, NULL);
1122 }
1123 spin_unlock_bh(&sc->sc_pcu_lock);
1124
Felix Fietkau04535312014-06-11 16:17:51 +05301125 list_del(&avp->list);
Ben Greear48014162011-01-15 19:13:48 +00001126 sc->nvifs--;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001127 sc->tx99_vif = NULL;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001128
Ben Greear48014162011-01-15 19:13:48 +00001129 if (ath9k_uses_beacons(vif->type))
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301130 ath9k_beacon_remove_slot(sc, vif);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001131
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301132 ath9k_ps_wakeup(sc);
Ben Greear48014162011-01-15 19:13:48 +00001133 ath9k_calculate_summary_state(hw, NULL);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301134 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301135
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001136 ath_tx_node_cleanup(sc, &avp->mcast_node);
1137
Sujith141b38b2009-02-04 08:10:07 +05301138 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001139}
1140
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301141static void ath9k_enable_ps(struct ath_softc *sc)
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301142{
Pavel Roskin30691682010-03-31 18:05:31 -04001143 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301144 struct ath_common *common = ath9k_hw_common(ah);
Pavel Roskin30691682010-03-31 18:05:31 -04001145
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001146 if (config_enabled(CONFIG_ATH9K_TX99))
1147 return;
1148
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301149 sc->ps_enabled = true;
Pavel Roskin30691682010-03-31 18:05:31 -04001150 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1151 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1152 ah->imask |= ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001153 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301154 }
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001155 ath9k_hw_setrxabort(ah, 1);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301156 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301157 ath_dbg(common, PS, "PowerSave enabled\n");
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301158}
1159
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301160static void ath9k_disable_ps(struct ath_softc *sc)
1161{
1162 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301163 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301164
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001165 if (config_enabled(CONFIG_ATH9K_TX99))
1166 return;
1167
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301168 sc->ps_enabled = false;
1169 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1170 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1171 ath9k_hw_setrxabort(ah, 0);
1172 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1173 PS_WAIT_FOR_CAB |
1174 PS_WAIT_FOR_PSPOLL_DATA |
1175 PS_WAIT_FOR_TX_ACK);
1176 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1177 ah->imask &= ~ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001178 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301179 }
1180 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301181 ath_dbg(common, PS, "PowerSave disabled\n");
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301182}
1183
Simon Wunderliche93d0832013-01-08 14:48:58 +01001184void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
1185{
1186 struct ath_softc *sc = hw->priv;
1187 struct ath_hw *ah = sc->sc_ah;
1188 struct ath_common *common = ath9k_hw_common(ah);
1189 u32 rxfilter;
1190
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001191 if (config_enabled(CONFIG_ATH9K_TX99))
1192 return;
1193
Simon Wunderliche93d0832013-01-08 14:48:58 +01001194 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1195 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1196 return;
1197 }
1198
1199 ath9k_ps_wakeup(sc);
1200 rxfilter = ath9k_hw_getrxfilter(ah);
1201 ath9k_hw_setrxfilter(ah, rxfilter |
1202 ATH9K_RX_FILTER_PHYRADAR |
1203 ATH9K_RX_FILTER_PHYERR);
1204
1205 /* TODO: usually this should not be neccesary, but for some reason
1206 * (or in some mode?) the trigger must be called after the
1207 * configuration, otherwise the register will have its values reset
1208 * (on my ar9220 to value 0x01002310)
1209 */
1210 ath9k_spectral_scan_config(hw, sc->spectral_mode);
1211 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
1212 ath9k_ps_restore(sc);
1213}
1214
1215int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
1216 enum spectral_mode spectral_mode)
1217{
1218 struct ath_softc *sc = hw->priv;
1219 struct ath_hw *ah = sc->sc_ah;
1220 struct ath_common *common = ath9k_hw_common(ah);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001221
1222 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1223 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1224 return -1;
1225 }
1226
Simon Wunderliche93d0832013-01-08 14:48:58 +01001227 switch (spectral_mode) {
1228 case SPECTRAL_DISABLED:
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001229 sc->spec_config.enabled = 0;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001230 break;
1231 case SPECTRAL_BACKGROUND:
1232 /* send endless samples.
1233 * TODO: is this really useful for "background"?
1234 */
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001235 sc->spec_config.endless = 1;
1236 sc->spec_config.enabled = 1;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001237 break;
1238 case SPECTRAL_CHANSCAN:
Simon Wunderliche93d0832013-01-08 14:48:58 +01001239 case SPECTRAL_MANUAL:
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001240 sc->spec_config.endless = 0;
1241 sc->spec_config.enabled = 1;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001242 break;
1243 default:
1244 return -1;
1245 }
1246
1247 ath9k_ps_wakeup(sc);
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001248 ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001249 ath9k_ps_restore(sc);
1250
1251 sc->spectral_mode = spectral_mode;
1252
1253 return 0;
1254}
1255
Johannes Berge8975582008-10-09 12:18:51 +02001256static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001258 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001259 struct ath_hw *ah = sc->sc_ah;
1260 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berge8975582008-10-09 12:18:51 +02001261 struct ieee80211_conf *conf = &hw->conf;
Felix Fietkaufbbcd142014-06-11 16:17:49 +05301262 struct ath_chanctx *ctx = sc->cur_chan;
Felix Fietkau75600ab2012-04-12 20:36:31 +02001263 bool reset_channel = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001264
Felix Fietkauc0c11742011-11-16 13:08:41 +01001265 ath9k_ps_wakeup(sc);
Sujithaa33de02008-12-18 11:40:16 +05301266 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301267
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001268 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Felix Fietkau7545daf2011-01-24 19:23:16 +01001269 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301270 if (sc->ps_idle) {
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001271 ath_cancel_work(sc);
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301272 ath9k_stop_btcoex(sc);
1273 } else {
1274 ath9k_start_btcoex(sc);
Felix Fietkau75600ab2012-04-12 20:36:31 +02001275 /*
1276 * The chip needs a reset to properly wake up from
1277 * full sleep
1278 */
1279 reset_channel = ah->chip_fullsleep;
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301280 }
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001281 }
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001282
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001283 /*
1284 * We just prepare to enable PS. We have to wait until our AP has
1285 * ACK'd our null data frame to disable RX otherwise we'll ignore
1286 * those ACKs and end up retransmitting the same null data frames.
1287 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1288 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301289 if (changed & IEEE80211_CONF_CHANGE_PS) {
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001290 unsigned long flags;
1291 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301292 if (conf->flags & IEEE80211_CONF_PS)
1293 ath9k_enable_ps(sc);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301294 else
1295 ath9k_disable_ps(sc);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001296 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301297 }
1298
Sujith199afd92010-01-08 10:36:13 +05301299 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1300 if (conf->flags & IEEE80211_CONF_MONITOR) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001301 ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301302 sc->sc_ah->is_monitoring = true;
1303 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -08001304 ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301305 sc->sc_ah->is_monitoring = false;
Sujith199afd92010-01-08 10:36:13 +05301306 }
1307 }
1308
Felix Fietkau75600ab2012-04-12 20:36:31 +02001309 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
Felix Fietkaufbbcd142014-06-11 16:17:49 +05301310 ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
1311 if (ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef) < 0) {
Joe Perches38002762010-12-02 19:12:36 -08001312 ath_err(common, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301313 mutex_unlock(&sc->mutex);
Rajkumar Manoharan8389fb32012-06-11 12:19:30 +05301314 ath9k_ps_restore(sc);
Sujithe11602b2008-11-27 09:46:27 +05301315 return -EINVAL;
1316 }
Sujith094d05d2008-12-12 11:57:43 +05301317 }
Sujith86b89ee2008-08-07 10:54:57 +05301318
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001319 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001320 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +05301321 sc->cur_chan->txpower = 2 * conf->power_level;
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +05301322 ath9k_cmn_update_txpow(ah, sc->curtxpow,
Felix Fietkaubc7e1be2014-06-11 16:17:50 +05301323 sc->cur_chan->txpower, &sc->curtxpow);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001324 }
1325
Sujithaa33de02008-12-18 11:40:16 +05301326 mutex_unlock(&sc->mutex);
Felix Fietkauc0c11742011-11-16 13:08:41 +01001327 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301328
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001329 return 0;
1330}
1331
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001332#define SUPPORTED_FILTERS \
1333 (FIF_PROMISC_IN_BSS | \
1334 FIF_ALLMULTI | \
1335 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001336 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001337 FIF_OTHER_BSS | \
1338 FIF_BCN_PRBRESP_PROMISC | \
Jouni Malinen9c1d8e42010-10-13 17:29:31 +03001339 FIF_PROBE_REQ | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001340 FIF_FCSFAIL)
1341
Sujith7dcfdcd2008-08-11 14:03:13 +05301342/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001343static void ath9k_configure_filter(struct ieee80211_hw *hw,
1344 unsigned int changed_flags,
1345 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001346 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001347{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001348 struct ath_softc *sc = hw->priv;
Sujith7dcfdcd2008-08-11 14:03:13 +05301349 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001350
1351 changed_flags &= SUPPORTED_FILTERS;
1352 *total_flags &= SUPPORTED_FILTERS;
1353
Sujithb77f4832008-12-07 21:44:03 +05301354 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001355 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301356 rfilt = ath_calcrxfilter(sc);
1357 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001358 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301359
Joe Perchesd2182b62011-12-15 14:55:53 -08001360 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
1361 rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001362}
1363
Johannes Berg4ca77862010-02-19 19:06:56 +01001364static int ath9k_sta_add(struct ieee80211_hw *hw,
1365 struct ieee80211_vif *vif,
1366 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001367{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001368 struct ath_softc *sc = hw->priv;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001369 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1370 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1371 struct ieee80211_key_conf ps_key = { };
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001372 int key;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001373
Ben Greear7e1e3862011-11-03 11:33:13 -07001374 ath_node_attach(sc, sta, vif);
Felix Fietkauf59a59f2011-05-10 20:52:22 +02001375
1376 if (vif->type != NL80211_IFTYPE_AP &&
1377 vif->type != NL80211_IFTYPE_AP_VLAN)
1378 return 0;
1379
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001380 key = ath_key_config(common, vif, sta, &ps_key);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301381 if (key > 0) {
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001382 an->ps_key = key;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301383 an->key_idx[0] = key;
1384 }
Johannes Berg4ca77862010-02-19 19:06:56 +01001385
1386 return 0;
1387}
1388
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001389static void ath9k_del_ps_key(struct ath_softc *sc,
1390 struct ieee80211_vif *vif,
1391 struct ieee80211_sta *sta)
1392{
1393 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1394 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1395 struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
1396
1397 if (!an->ps_key)
1398 return;
1399
1400 ath_key_delete(common, &ps_key);
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001401 an->ps_key = 0;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301402 an->key_idx[0] = 0;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001403}
1404
Johannes Berg4ca77862010-02-19 19:06:56 +01001405static int ath9k_sta_remove(struct ieee80211_hw *hw,
1406 struct ieee80211_vif *vif,
1407 struct ieee80211_sta *sta)
1408{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001409 struct ath_softc *sc = hw->priv;
Johannes Berg4ca77862010-02-19 19:06:56 +01001410
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001411 ath9k_del_ps_key(sc, vif, sta);
Johannes Berg4ca77862010-02-19 19:06:56 +01001412 ath_node_detach(sc, sta);
1413
1414 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001415}
1416
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301417static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
1418 struct ath_node *an,
1419 bool set)
1420{
1421 int i;
1422
1423 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1424 if (!an->key_idx[i])
1425 continue;
1426 ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
1427 }
1428}
1429
Felix Fietkau55195412011-04-17 23:28:09 +02001430static void ath9k_sta_notify(struct ieee80211_hw *hw,
1431 struct ieee80211_vif *vif,
1432 enum sta_notify_cmd cmd,
1433 struct ieee80211_sta *sta)
1434{
1435 struct ath_softc *sc = hw->priv;
1436 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1437
1438 switch (cmd) {
1439 case STA_NOTIFY_SLEEP:
1440 an->sleeping = true;
Johannes Berg042ec452011-09-29 16:04:26 +02001441 ath_tx_aggr_sleep(sta, sc, an);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301442 ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
Felix Fietkau55195412011-04-17 23:28:09 +02001443 break;
1444 case STA_NOTIFY_AWAKE:
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301445 ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
Felix Fietkau55195412011-04-17 23:28:09 +02001446 an->sleeping = false;
1447 ath_tx_aggr_wakeup(sc, an);
1448 break;
1449 }
1450}
1451
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001452static int ath9k_conf_tx(struct ieee80211_hw *hw,
1453 struct ieee80211_vif *vif, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001454 const struct ieee80211_tx_queue_params *params)
1455{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001456 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001457 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau066dae92010-11-07 14:59:39 +01001458 struct ath_txq *txq;
Sujithea9880f2008-08-07 10:53:10 +05301459 struct ath9k_tx_queue_info qi;
Felix Fietkau066dae92010-11-07 14:59:39 +01001460 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001461
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301462 if (queue >= IEEE80211_NUM_ACS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001463 return 0;
1464
Felix Fietkau066dae92010-11-07 14:59:39 +01001465 txq = sc->tx.txq_map[queue];
1466
Felix Fietkau96f372c2011-04-07 19:07:17 +02001467 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301468 mutex_lock(&sc->mutex);
1469
Sujith1ffb0612009-03-30 15:28:46 +05301470 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1471
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001472 qi.tqi_aifs = params->aifs;
1473 qi.tqi_cwmin = params->cw_min;
1474 qi.tqi_cwmax = params->cw_max;
Felix Fietkau531bd072012-07-15 19:53:34 +02001475 qi.tqi_burstTime = params->txop * 32;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001476
Joe Perchesd2182b62011-12-15 14:55:53 -08001477 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -08001478 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1479 queue, txq->axq_qnum, params->aifs, params->cw_min,
1480 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001481
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001482 ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
Felix Fietkau066dae92010-11-07 14:59:39 +01001483 ret = ath_txq_update(sc, txq->axq_qnum, &qi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001484 if (ret)
Joe Perches38002762010-12-02 19:12:36 -08001485 ath_err(common, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001486
Sujith141b38b2009-02-04 08:10:07 +05301487 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001488 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001490 return ret;
1491}
1492
1493static int ath9k_set_key(struct ieee80211_hw *hw,
1494 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001495 struct ieee80211_vif *vif,
1496 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001497 struct ieee80211_key_conf *key)
1498{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001499 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001500 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301501 struct ath_node *an = NULL;
1502 int ret = 0, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001503
John W. Linville3e6109c2011-01-05 09:39:17 -05001504 if (ath9k_modparam_nohwcrypt)
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001505 return -ENOSPC;
1506
Chun-Yeow Yeoh5bd5e9a2011-12-07 12:45:46 -08001507 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1508 vif->type == NL80211_IFTYPE_MESH_POINT) &&
Jouni Malinencfdc9a82011-03-23 14:52:19 +02001509 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1510 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1511 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1512 /*
1513 * For now, disable hw crypto for the RSN IBSS group keys. This
1514 * could be optimized in the future to use a modified key cache
1515 * design to support per-STA RX GTK, but until that gets
1516 * implemented, use of software crypto for group addressed
1517 * frames is a acceptable to allow RSN IBSS to be used.
1518 */
1519 return -EOPNOTSUPP;
1520 }
1521
Sujith141b38b2009-02-04 08:10:07 +05301522 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301523 ath9k_ps_wakeup(sc);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301524 ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
1525 if (sta)
1526 an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001527
1528 switch (cmd) {
1529 case SET_KEY:
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001530 if (sta)
1531 ath9k_del_ps_key(sc, vif, sta);
1532
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301533 key->hw_key_idx = 0;
Bruno Randolf040e5392010-09-08 16:05:04 +09001534 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001535 if (ret >= 0) {
1536 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001537 /* push IV and Michael MIC generation to stack */
1538 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Johannes Berg97359d12010-08-10 09:46:38 +02001539 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301540 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg97359d12010-08-10 09:46:38 +02001541 if (sc->sc_ah->sw_mgmt_crypto &&
1542 key->cipher == WLAN_CIPHER_SUITE_CCMP)
Johannes Berge548c492012-09-04 17:08:23 +02001543 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001544 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001545 }
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301546 if (an && key->hw_key_idx) {
1547 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1548 if (an->key_idx[i])
1549 continue;
1550 an->key_idx[i] = key->hw_key_idx;
1551 break;
1552 }
1553 WARN_ON(i == ARRAY_SIZE(an->key_idx));
1554 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001555 break;
1556 case DISABLE_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001557 ath_key_delete(common, key);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301558 if (an) {
1559 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1560 if (an->key_idx[i] != key->hw_key_idx)
1561 continue;
1562 an->key_idx[i] = 0;
1563 break;
1564 }
1565 }
1566 key->hw_key_idx = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001567 break;
1568 default:
1569 ret = -EINVAL;
1570 }
1571
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301572 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301573 mutex_unlock(&sc->mutex);
1574
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001575 return ret;
1576}
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301577
1578static void ath9k_set_assoc_state(struct ath_softc *sc,
1579 struct ieee80211_vif *vif)
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301580{
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301581 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301582 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301583 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Sujith Manoharan07c15a32012-06-04 20:24:07 +05301584 unsigned long flags;
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301585
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001586 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301587 avp->primary_sta_vif = true;
1588
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301589 /*
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301590 * Set the AID, BSSID and do beacon-sync only when
1591 * the HW opmode is STATION.
1592 *
1593 * But the primary bit is set above in any case.
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301594 */
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301595 if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
1596 return;
1597
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301598 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1599 common->curaid = bss_conf->aid;
1600 ath9k_hw_write_associd(sc->sc_ah);
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301601
Oleksij Rempel32efb0c2014-02-04 10:27:39 +01001602 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301603 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301604
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301605 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1606 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
1607 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1608
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +05301609 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1610 ath9k_mci_update_wlan_channels(sc, false);
1611
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301612 ath_dbg(common, CONFIG,
1613 "Primary Station interface: %pM, BSSID: %pM\n",
1614 vif->addr, common->curbssid);
1615}
1616
1617static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1618{
1619 struct ath_softc *sc = data;
1620 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001621 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301622
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001623 if (test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags))
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301624 return;
1625
1626 if (bss_conf->assoc)
1627 ath9k_set_assoc_state(sc, vif);
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301628}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001629
Felix Fietkaud463af42014-04-06 00:37:03 +02001630void ath9k_p2p_ps_timer(void *priv)
1631{
1632 struct ath_softc *sc = priv;
1633 struct ath_vif *avp = sc->p2p_ps_vif;
1634 struct ieee80211_vif *vif;
1635 struct ieee80211_sta *sta;
1636 struct ath_node *an;
1637 u32 tsf;
1638
1639 if (!avp)
1640 return;
1641
1642 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1643 if (!avp->noa.absent)
1644 tsf += ATH_P2P_PS_STOP_TIME;
1645
1646 if (!avp->noa.has_next_tsf ||
1647 avp->noa.next_tsf - tsf > BIT(31))
1648 ieee80211_update_p2p_noa(&avp->noa, tsf);
1649
1650 ath9k_update_p2p_ps_timer(sc, avp);
1651
1652 rcu_read_lock();
1653
1654 vif = avp->vif;
1655 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1656 if (!sta)
1657 goto out;
1658
1659 an = (void *) sta->drv_priv;
1660 if (an->sleeping == !!avp->noa.absent)
1661 goto out;
1662
1663 an->sleeping = avp->noa.absent;
1664 if (an->sleeping)
1665 ath_tx_aggr_sleep(sta, sc, an);
1666 else
1667 ath_tx_aggr_wakeup(sc, an);
1668
1669out:
1670 rcu_read_unlock();
1671}
1672
1673void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1674{
1675 struct ath_vif *avp = (void *)vif->drv_priv;
Felix Fietkaud463af42014-04-06 00:37:03 +02001676 u32 tsf;
1677
1678 if (!sc->p2p_ps_timer)
1679 return;
1680
1681 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
1682 return;
1683
1684 sc->p2p_ps_vif = avp;
Rajkumar Manoharan60ccc102014-05-27 16:58:02 +05301685 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1686 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1687 ath9k_update_p2p_ps_timer(sc, avp);
Felix Fietkaud463af42014-04-06 00:37:03 +02001688}
1689
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1691 struct ieee80211_vif *vif,
1692 struct ieee80211_bss_conf *bss_conf,
1693 u32 changed)
1694{
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301695#define CHECK_ANI \
1696 (BSS_CHANGED_ASSOC | \
1697 BSS_CHANGED_IBSS | \
1698 BSS_CHANGED_BEACON_ENABLED)
1699
Felix Fietkau9ac586152011-01-24 19:23:18 +01001700 struct ath_softc *sc = hw->priv;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001701 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001702 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001703 struct ath_vif *avp = (void *)vif->drv_priv;
Rajkumar Manoharan60ccc102014-05-27 16:58:02 +05301704 unsigned long flags;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001705 int slottime;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001706
Felix Fietkau96f372c2011-04-07 19:07:17 +02001707 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301708 mutex_lock(&sc->mutex);
1709
Rajkumar Manoharan9f619032012-03-10 05:06:49 +05301710 if (changed & BSS_CHANGED_ASSOC) {
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301711 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
1712 bss_conf->bssid, bss_conf->assoc);
Sujithc6089cc2009-11-16 11:40:48 +05301713
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301714 if (avp->primary_sta_vif && !bss_conf->assoc) {
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001715 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301716 avp->primary_sta_vif = false;
1717
1718 if (ah->opmode == NL80211_IFTYPE_STATION)
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001719 clear_bit(ATH_OP_BEACONS, &common->op_flags);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301720 }
1721
Johannes Berg8b2c9822012-11-06 20:23:30 +01001722 ieee80211_iterate_active_interfaces_atomic(
1723 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1724 ath9k_bss_assoc_iter, sc);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301725
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001726 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags) &&
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301727 ah->opmode == NL80211_IFTYPE_STATION) {
1728 memset(common->curbssid, 0, ETH_ALEN);
1729 common->curaid = 0;
1730 ath9k_hw_write_associd(sc->sc_ah);
Rajkumar Manoharan50072eb2012-10-12 14:07:22 +05301731 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1732 ath9k_mci_update_wlan_channels(sc, true);
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301733 }
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001734 }
1735
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301736 if (changed & BSS_CHANGED_IBSS) {
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301737 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1738 common->curaid = bss_conf->aid;
1739 ath9k_hw_write_associd(sc->sc_ah);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301740 }
1741
Sujith Manoharanef4ad632012-07-17 17:15:56 +05301742 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
Felix Fietkauc32e4e52013-12-19 18:01:49 +01001743 (changed & BSS_CHANGED_BEACON_INT))
1744 ath9k_beacon_config(sc, vif, changed);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001745
Felix Fietkau0005baf2010-01-15 02:33:40 +01001746 if (changed & BSS_CHANGED_ERP_SLOT) {
1747 if (bss_conf->use_short_slot)
1748 slottime = 9;
1749 else
1750 slottime = 20;
1751 if (vif->type == NL80211_IFTYPE_AP) {
1752 /*
1753 * Defer update, so that connected stations can adjust
1754 * their settings at the same time.
1755 * See beacon.c for more details
1756 */
1757 sc->beacon.slottime = slottime;
1758 sc->beacon.updateslot = UPDATE;
1759 } else {
1760 ah->slottime = slottime;
1761 ath9k_hw_init_global_settings(ah);
1762 }
1763 }
1764
Felix Fietkaud463af42014-04-06 00:37:03 +02001765 if (changed & BSS_CHANGED_P2P_PS) {
1766 spin_lock_bh(&sc->sc_pcu_lock);
Rajkumar Manoharan60ccc102014-05-27 16:58:02 +05301767 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1768 if (!(sc->ps_flags & PS_BEACON_SYNC))
1769 ath9k_update_p2p_ps(sc, vif);
1770 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Felix Fietkaud463af42014-04-06 00:37:03 +02001771 spin_unlock_bh(&sc->sc_pcu_lock);
1772 }
1773
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301774 if (changed & CHECK_ANI)
1775 ath_check_ani(sc);
1776
Sujith141b38b2009-02-04 08:10:07 +05301777 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001778 ath9k_ps_restore(sc);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301779
1780#undef CHECK_ANI
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001781}
1782
Eliad Peller37a41b42011-09-21 14:06:11 +03001783static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001785 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786 u64 tsf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001787
Sujith141b38b2009-02-04 08:10:07 +05301788 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301789 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301790 tsf = ath9k_hw_gettsf64(sc->sc_ah);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301791 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301792 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001793
1794 return tsf;
1795}
1796
Eliad Peller37a41b42011-09-21 14:06:11 +03001797static void ath9k_set_tsf(struct ieee80211_hw *hw,
1798 struct ieee80211_vif *vif,
1799 u64 tsf)
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001800{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001801 struct ath_softc *sc = hw->priv;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001802
Sujith141b38b2009-02-04 08:10:07 +05301803 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301804 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301805 ath9k_hw_settsf64(sc->sc_ah, tsf);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301806 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301807 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001808}
1809
Eliad Peller37a41b42011-09-21 14:06:11 +03001810static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001811{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001812 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001813
Sujith141b38b2009-02-04 08:10:07 +05301814 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001815
1816 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301817 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001818 ath9k_ps_restore(sc);
1819
Sujith141b38b2009-02-04 08:10:07 +05301820 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001821}
1822
1823static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01001824 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05301825 enum ieee80211_ampdu_mlme_action action,
1826 struct ieee80211_sta *sta,
Johannes Berg0b01f0302011-01-18 13:51:05 +01001827 u16 tid, u16 *ssn, u8 buf_size)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001828{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001829 struct ath_softc *sc = hw->priv;
Felix Fietkau16e23422013-05-17 12:58:24 +02001830 bool flush = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001831 int ret = 0;
1832
Sujith Manoharan7ca7c772013-05-08 05:03:32 +05301833 mutex_lock(&sc->mutex);
Johannes Berg85ad1812010-06-10 10:21:49 +02001834
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001835 switch (action) {
1836 case IEEE80211_AMPDU_RX_START:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001837 break;
1838 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001839 break;
1840 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001841 ath9k_ps_wakeup(sc);
Felix Fietkau231c3a12010-09-20 19:35:28 +02001842 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1843 if (!ret)
1844 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001845 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001846 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02001847 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1848 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Felix Fietkau16e23422013-05-17 12:58:24 +02001849 flush = true;
1850 case IEEE80211_AMPDU_TX_STOP_CONT:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001851 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301852 ath_tx_aggr_stop(sc, sta, tid);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001853 if (!flush)
Felix Fietkau16e23422013-05-17 12:58:24 +02001854 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001855 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001856 break;
Johannes Bergb1720232009-03-23 17:28:39 +01001857 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001858 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05301859 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001860 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05301861 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001862 default:
Joe Perches38002762010-12-02 19:12:36 -08001863 ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001864 }
1865
Sujith Manoharan7ca7c772013-05-08 05:03:32 +05301866 mutex_unlock(&sc->mutex);
Johannes Berg85ad1812010-06-10 10:21:49 +02001867
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001868 return ret;
1869}
1870
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001871static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
1872 struct survey_info *survey)
1873{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001874 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001875 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39162db2010-09-29 19:12:06 +02001876 struct ieee80211_supported_band *sband;
Felix Fietkau34300982010-10-10 18:21:52 +02001877 struct ieee80211_channel *chan;
Felix Fietkau34300982010-10-10 18:21:52 +02001878 int pos;
1879
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001880 if (config_enabled(CONFIG_ATH9K_TX99))
1881 return -EOPNOTSUPP;
1882
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301883 spin_lock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001884 if (idx == 0)
1885 ath_update_survey_stats(sc);
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001886
Felix Fietkau39162db2010-09-29 19:12:06 +02001887 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
1888 if (sband && idx >= sband->n_channels) {
1889 idx -= sband->n_channels;
1890 sband = NULL;
1891 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001892
Felix Fietkau39162db2010-09-29 19:12:06 +02001893 if (!sband)
1894 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
1895
Felix Fietkau34300982010-10-10 18:21:52 +02001896 if (!sband || idx >= sband->n_channels) {
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301897 spin_unlock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001898 return -ENOENT;
Felix Fietkau4f1a5a42010-09-29 17:15:28 +02001899 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001900
Felix Fietkau34300982010-10-10 18:21:52 +02001901 chan = &sband->channels[idx];
1902 pos = chan->hw_value;
1903 memcpy(survey, &sc->survey[pos], sizeof(*survey));
1904 survey->channel = chan;
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301905 spin_unlock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001906
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001907 return 0;
1908}
1909
Felix Fietkaue239d852010-01-15 02:34:58 +01001910static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
1911{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001912 struct ath_softc *sc = hw->priv;
Felix Fietkaue239d852010-01-15 02:34:58 +01001913 struct ath_hw *ah = sc->sc_ah;
1914
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001915 if (config_enabled(CONFIG_ATH9K_TX99))
1916 return;
1917
Felix Fietkaue239d852010-01-15 02:34:58 +01001918 mutex_lock(&sc->mutex);
1919 ah->coverage_class = coverage_class;
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301920
1921 ath9k_ps_wakeup(sc);
Felix Fietkaue239d852010-01-15 02:34:58 +01001922 ath9k_hw_init_global_settings(ah);
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301923 ath9k_ps_restore(sc);
1924
Felix Fietkaue239d852010-01-15 02:34:58 +01001925 mutex_unlock(&sc->mutex);
1926}
1927
Felix Fietkau10e23182013-11-11 22:23:35 +01001928static bool ath9k_has_tx_pending(struct ath_softc *sc)
1929{
Geert Uytterhoevenf7838072014-01-26 11:53:21 +01001930 int i, npend = 0;
Felix Fietkau10e23182013-11-11 22:23:35 +01001931
1932 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1933 if (!ATH_TXQ_SETUP(sc, i))
1934 continue;
1935
1936 if (!sc->tx.txq[i].axq_depth)
1937 continue;
1938
1939 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
1940 if (npend)
1941 break;
1942 }
1943
1944 return !!npend;
1945}
1946
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02001947static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1948 u32 queues, bool drop)
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001949{
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001950 struct ath_softc *sc = hw->priv;
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301951 struct ath_hw *ah = sc->sc_ah;
1952 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau10e23182013-11-11 22:23:35 +01001953 int timeout = HZ / 5; /* 200 ms */
Rajkumar Manoharan2f6fc352011-04-28 15:31:57 +05301954 bool drain_txq;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001955
1956 mutex_lock(&sc->mutex);
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001957 cancel_delayed_work_sync(&sc->tx_complete_work);
1958
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301959 if (ah->ah_flags & AH_UNPLUGGED) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001960 ath_dbg(common, ANY, "Device has been unplugged!\n");
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301961 mutex_unlock(&sc->mutex);
1962 return;
1963 }
1964
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001965 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001966 ath_dbg(common, ANY, "Device not present\n");
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301967 mutex_unlock(&sc->mutex);
1968 return;
1969 }
1970
Felix Fietkau10e23182013-11-11 22:23:35 +01001971 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
1972 timeout) > 0)
1973 drop = false;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001974
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001975 if (drop) {
1976 ath9k_ps_wakeup(sc);
1977 spin_lock_bh(&sc->sc_pcu_lock);
Felix Fietkau13815592013-01-20 18:51:53 +01001978 drain_txq = ath_drain_all_txq(sc);
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001979 spin_unlock_bh(&sc->sc_pcu_lock);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001980
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001981 if (!drain_txq)
Felix Fietkau13815592013-01-20 18:51:53 +01001982 ath_reset(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001983
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001984 ath9k_ps_restore(sc);
1985 ieee80211_wake_queues(hw);
1986 }
Senthil Balasubramaniand78f4b32011-03-23 23:07:22 +05301987
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001988 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
1989 mutex_unlock(&sc->mutex);
1990}
1991
Vivek Natarajan15b91e82011-04-06 11:41:11 +05301992static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
1993{
1994 struct ath_softc *sc = hw->priv;
1995 int i;
1996
1997 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1998 if (!ATH_TXQ_SETUP(sc, i))
1999 continue;
2000
2001 if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
2002 return true;
2003 }
2004 return false;
2005}
2006
Mohammed Shafi Shajakhan5595f112011-05-19 18:08:57 +05302007static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
Felix Fietkauba4903f2011-05-17 21:09:54 +02002008{
2009 struct ath_softc *sc = hw->priv;
2010 struct ath_hw *ah = sc->sc_ah;
2011 struct ieee80211_vif *vif;
2012 struct ath_vif *avp;
2013 struct ath_buf *bf;
2014 struct ath_tx_status ts;
Felix Fietkau4286df62012-02-27 19:58:40 +01002015 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Felix Fietkauba4903f2011-05-17 21:09:54 +02002016 int status;
2017
2018 vif = sc->beacon.bslot[0];
2019 if (!vif)
2020 return 0;
2021
Sujith Manoharanaa45fe92012-07-17 17:16:03 +05302022 if (!vif->bss_conf.enable_beacon)
Felix Fietkauba4903f2011-05-17 21:09:54 +02002023 return 0;
2024
Sujith Manoharanaa45fe92012-07-17 17:16:03 +05302025 avp = (void *)vif->drv_priv;
2026
Felix Fietkau4286df62012-02-27 19:58:40 +01002027 if (!sc->beacon.tx_processed && !edma) {
Felix Fietkauba4903f2011-05-17 21:09:54 +02002028 tasklet_disable(&sc->bcon_tasklet);
2029
2030 bf = avp->av_bcbuf;
2031 if (!bf || !bf->bf_mpdu)
2032 goto skip;
2033
2034 status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
2035 if (status == -EINPROGRESS)
2036 goto skip;
2037
2038 sc->beacon.tx_processed = true;
2039 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
2040
2041skip:
2042 tasklet_enable(&sc->bcon_tasklet);
2043 }
2044
2045 return sc->beacon.tx_last;
2046}
2047
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302048static int ath9k_get_stats(struct ieee80211_hw *hw,
2049 struct ieee80211_low_level_stats *stats)
2050{
2051 struct ath_softc *sc = hw->priv;
2052 struct ath_hw *ah = sc->sc_ah;
2053 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
2054
2055 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
2056 stats->dot11RTSFailureCount = mib_stats->rts_bad;
2057 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
2058 stats->dot11RTSSuccessCount = mib_stats->rts_good;
2059 return 0;
2060}
2061
Felix Fietkau43c35282011-09-03 01:40:27 +02002062static u32 fill_chainmask(u32 cap, u32 new)
2063{
2064 u32 filled = 0;
2065 int i;
2066
2067 for (i = 0; cap && new; i++, cap >>= 1) {
2068 if (!(cap & BIT(0)))
2069 continue;
2070
2071 if (new & BIT(0))
2072 filled |= BIT(i);
2073
2074 new >>= 1;
2075 }
2076
2077 return filled;
2078}
2079
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002080static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
2081{
Felix Fietkaufea92cb2013-01-20 21:55:22 +01002082 if (AR_SREV_9300_20_OR_LATER(ah))
2083 return true;
2084
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002085 switch (val & 0x7) {
2086 case 0x1:
2087 case 0x3:
2088 case 0x7:
2089 return true;
2090 case 0x2:
2091 return (ah->caps.rx_chainmask == 1);
2092 default:
2093 return false;
2094 }
2095}
2096
Felix Fietkau43c35282011-09-03 01:40:27 +02002097static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2098{
2099 struct ath_softc *sc = hw->priv;
2100 struct ath_hw *ah = sc->sc_ah;
2101
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002102 if (ah->caps.rx_chainmask != 1)
2103 rx_ant |= tx_ant;
2104
2105 if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
Felix Fietkau43c35282011-09-03 01:40:27 +02002106 return -EINVAL;
2107
2108 sc->ant_rx = rx_ant;
2109 sc->ant_tx = tx_ant;
2110
2111 if (ah->caps.rx_chainmask == 1)
2112 return 0;
2113
2114 /* AR9100 runs into calibration issues if not all rx chains are enabled */
2115 if (AR_SREV_9100(ah))
2116 ah->rxchainmask = 0x7;
2117 else
2118 ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
2119
2120 ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
Oleksij Rempelb57ba3b2014-02-25 14:48:55 +01002121 ath9k_cmn_reload_chainmask(ah);
Felix Fietkau43c35282011-09-03 01:40:27 +02002122
2123 return 0;
2124}
2125
2126static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2127{
2128 struct ath_softc *sc = hw->priv;
2129
2130 *tx_ant = sc->ant_tx;
2131 *rx_ant = sc->ant_rx;
2132 return 0;
2133}
2134
Simon Wunderliche93d0832013-01-08 14:48:58 +01002135static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2136{
2137 struct ath_softc *sc = hw->priv;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002138 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2139 set_bit(ATH_OP_SCANNING, &common->op_flags);
Simon Wunderliche93d0832013-01-08 14:48:58 +01002140}
2141
2142static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2143{
2144 struct ath_softc *sc = hw->priv;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002145 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2146 clear_bit(ATH_OP_SCANNING, &common->op_flags);
Simon Wunderliche93d0832013-01-08 14:48:58 +01002147}
Mohammed Shafi Shajakhanb11e6402012-07-10 14:56:52 +05302148
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002149struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002150 .tx = ath9k_tx,
2151 .start = ath9k_start,
2152 .stop = ath9k_stop,
2153 .add_interface = ath9k_add_interface,
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05302154 .change_interface = ath9k_change_interface,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002155 .remove_interface = ath9k_remove_interface,
2156 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002157 .configure_filter = ath9k_configure_filter,
Johannes Berg4ca77862010-02-19 19:06:56 +01002158 .sta_add = ath9k_sta_add,
2159 .sta_remove = ath9k_sta_remove,
Felix Fietkau55195412011-04-17 23:28:09 +02002160 .sta_notify = ath9k_sta_notify,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002161 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002162 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002163 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002164 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002165 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002166 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002167 .ampdu_action = ath9k_ampdu_action,
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002168 .get_survey = ath9k_get_survey,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302169 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002170 .set_coverage_class = ath9k_set_coverage_class,
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08002171 .flush = ath9k_flush,
Vivek Natarajan15b91e82011-04-06 11:41:11 +05302172 .tx_frames_pending = ath9k_tx_frames_pending,
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302173 .tx_last_beacon = ath9k_tx_last_beacon,
Felix Fietkau86a22ac2013-06-07 18:12:01 +02002174 .release_buffered_frames = ath9k_release_buffered_frames,
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302175 .get_stats = ath9k_get_stats,
Felix Fietkau43c35282011-09-03 01:40:27 +02002176 .set_antenna = ath9k_set_antenna,
2177 .get_antenna = ath9k_get_antenna,
Ben Greearb90bd9d2012-05-15 15:33:25 -07002178
Sujith Manoharane60001e2013-10-28 12:22:04 +05302179#ifdef CONFIG_ATH9K_WOW
Mohammed Shafi Shajakhanb11e6402012-07-10 14:56:52 +05302180 .suspend = ath9k_suspend,
2181 .resume = ath9k_resume,
2182 .set_wakeup = ath9k_set_wakeup,
2183#endif
2184
Ben Greearb90bd9d2012-05-15 15:33:25 -07002185#ifdef CONFIG_ATH9K_DEBUGFS
2186 .get_et_sset_count = ath9k_get_et_sset_count,
Sujith Manoharana145daf2012-11-28 15:08:54 +05302187 .get_et_stats = ath9k_get_et_stats,
2188 .get_et_strings = ath9k_get_et_strings,
2189#endif
2190
Sujith Manoharan1cdbaf02014-01-13 07:29:27 +05302191#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
Sujith Manoharana145daf2012-11-28 15:08:54 +05302192 .sta_add_debugfs = ath9k_sta_add_debugfs,
Ben Greearb90bd9d2012-05-15 15:33:25 -07002193#endif
Simon Wunderliche93d0832013-01-08 14:48:58 +01002194 .sw_scan_start = ath9k_sw_scan_start,
2195 .sw_scan_complete = ath9k_sw_scan_complete,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002196};