blob: dd2d52eb35bbd512e269105d34be3ef88c41de68 [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
Sven Eckelmann313eb872012-06-25 07:15:22 +020022u8 ath9k_parse_mpdudensity(u8 mpdudensity)
Sujithff37e332008-11-24 12:07:55 +053023{
24 /*
25 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
26 * 0 for no restriction
27 * 1 for 1/4 us
28 * 2 for 1/2 us
29 * 3 for 1 us
30 * 4 for 2 us
31 * 5 for 4 us
32 * 6 for 8 us
33 * 7 for 16 us
34 */
35 switch (mpdudensity) {
36 case 0:
37 return 0;
38 case 1:
39 case 2:
40 case 3:
41 /* Our lower layer calculations limit our precision to
42 1 microsecond */
43 return 1;
44 case 4:
45 return 2;
46 case 5:
47 return 4;
48 case 6:
49 return 8;
50 case 7:
51 return 16;
52 default:
53 return 0;
54 }
55}
56
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080057static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq)
58{
59 bool pending = false;
60
61 spin_lock_bh(&txq->axq_lock);
62
Felix Fietkau04535312014-06-11 16:17:51 +053063 if (txq->axq_depth)
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080064 pending = true;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080065
Felix Fietkau04535312014-06-11 16:17:51 +053066 if (txq->mac80211_qnum >= 0) {
67 struct list_head *list;
68
69 list = &sc->cur_chan->acq[txq->mac80211_qnum];
70 if (!list_empty(list))
71 pending = true;
72 }
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080073 spin_unlock_bh(&txq->axq_lock);
74 return pending;
75}
76
Mohammed Shafi Shajakhan6d79cb42011-05-19 17:40:46 +053077static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070078{
79 unsigned long flags;
80 bool ret;
81
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070082 spin_lock_irqsave(&sc->sc_pm_lock, flags);
83 ret = ath9k_hw_setpower(sc->sc_ah, mode);
84 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070085
86 return ret;
87}
88
Felix Fietkaubf3dac52013-11-11 22:23:33 +010089void ath_ps_full_sleep(unsigned long data)
90{
91 struct ath_softc *sc = (struct ath_softc *) data;
92 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
93 bool reset;
94
95 spin_lock(&common->cc_lock);
96 ath_hw_cycle_counters_update(common);
97 spin_unlock(&common->cc_lock);
98
99 ath9k_hw_setrxabort(sc->sc_ah, 1);
100 ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
101
102 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
103}
104
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700105void ath9k_ps_wakeup(struct ath_softc *sc)
106{
Felix Fietkau898c9142010-10-12 14:02:53 +0200107 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700108 unsigned long flags;
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100109 enum ath9k_power_mode power_mode;
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700110
111 spin_lock_irqsave(&sc->sc_pm_lock, flags);
112 if (++sc->ps_usecount != 1)
113 goto unlock;
114
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100115 del_timer_sync(&sc->sleep_timer);
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100116 power_mode = sc->sc_ah->power_mode;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700117 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700118
Felix Fietkau898c9142010-10-12 14:02:53 +0200119 /*
120 * While the hardware is asleep, the cycle counters contain no
121 * useful data. Better clear them now so that they don't mess up
122 * survey data results.
123 */
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100124 if (power_mode != ATH9K_PM_AWAKE) {
125 spin_lock(&common->cc_lock);
126 ath_hw_cycle_counters_update(common);
127 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
Rajkumar Manoharanc9ae6ab2012-06-04 16:28:41 +0530128 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100129 spin_unlock(&common->cc_lock);
130 }
Felix Fietkau898c9142010-10-12 14:02:53 +0200131
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700132 unlock:
133 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
134}
135
136void ath9k_ps_restore(struct ath_softc *sc)
137{
Felix Fietkau898c9142010-10-12 14:02:53 +0200138 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200139 enum ath9k_power_mode mode;
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700140 unsigned long flags;
141
142 spin_lock_irqsave(&sc->sc_pm_lock, flags);
143 if (--sc->ps_usecount != 0)
144 goto unlock;
145
Sujith Manoharanad128862012-04-24 10:23:20 +0530146 if (sc->ps_idle) {
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100147 mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
148 goto unlock;
149 }
150
151 if (sc->ps_enabled &&
Sujith Manoharanad128862012-04-24 10:23:20 +0530152 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
153 PS_WAIT_FOR_CAB |
154 PS_WAIT_FOR_PSPOLL_DATA |
Rajkumar Manoharan424749c2012-10-10 23:03:02 +0530155 PS_WAIT_FOR_TX_ACK |
156 PS_WAIT_FOR_ANI))) {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200157 mode = ATH9K_PM_NETWORK_SLEEP;
Rajkumar Manoharan08d4df42012-07-01 19:53:54 +0530158 if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
159 ath9k_btcoex_stop_gen_timer(sc);
Sujith Manoharanad128862012-04-24 10:23:20 +0530160 } else {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200161 goto unlock;
Sujith Manoharanad128862012-04-24 10:23:20 +0530162 }
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200163
164 spin_lock(&common->cc_lock);
165 ath_hw_cycle_counters_update(common);
166 spin_unlock(&common->cc_lock);
167
Felix Fietkau1a8f0d392011-09-22 08:04:32 -0600168 ath9k_hw_setpower(sc->sc_ah, mode);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700169
170 unlock:
171 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
172}
173
Felix Fietkau9adcf442011-09-03 01:40:26 +0200174static void __ath_cancel_work(struct ath_softc *sc)
175{
176 cancel_work_sync(&sc->paprd_work);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200177 cancel_delayed_work_sync(&sc->tx_complete_work);
178 cancel_delayed_work_sync(&sc->hw_pll_work);
Sujith Manoharanfad29cd2012-06-25 13:54:22 +0530179
Sujith Manoharanbf525922012-06-27 14:15:59 +0530180#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
Sujith Manoharanfad29cd2012-06-25 13:54:22 +0530181 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
182 cancel_work_sync(&sc->mci_work);
Sujith Manoharanbf525922012-06-27 14:15:59 +0530183#endif
Felix Fietkau9adcf442011-09-03 01:40:26 +0200184}
185
Sujith Manoharane60001e2013-10-28 12:22:04 +0530186void ath_cancel_work(struct ath_softc *sc)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200187{
188 __ath_cancel_work(sc);
189 cancel_work_sync(&sc->hw_reset_work);
190}
191
Sujith Manoharane60001e2013-10-28 12:22:04 +0530192void ath_restart_work(struct ath_softc *sc)
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530193{
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530194 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
195
Sujith Manoharan19c36162013-08-20 10:05:59 +0530196 if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530197 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
198 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
199
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530200 ath_start_ani(sc);
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530201}
202
John W. Linville9ebea382013-01-28 13:54:03 -0500203static bool ath_prepare_reset(struct ath_softc *sc)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200204{
205 struct ath_hw *ah = sc->sc_ah;
Felix Fietkauceea2a52012-05-24 14:32:19 +0200206 bool ret = true;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200207
208 ieee80211_stop_queues(sc->hw);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +0530209 ath_stop_ani(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200210 ath9k_hw_disable_interrupts(ah);
211
Felix Fietkau13815592013-01-20 18:51:53 +0100212 if (!ath_drain_all_txq(sc))
Felix Fietkau9adcf442011-09-03 01:40:26 +0200213 ret = false;
214
Felix Fietkau0a62acb2013-01-20 18:51:52 +0100215 if (!ath_stoprecv(sc))
Felix Fietkauceea2a52012-05-24 14:32:19 +0200216 ret = false;
217
Felix Fietkau9adcf442011-09-03 01:40:26 +0200218 return ret;
219}
220
221static bool ath_complete_reset(struct ath_softc *sc, bool start)
222{
223 struct ath_hw *ah = sc->sc_ah;
224 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan196fb862012-06-04 20:24:13 +0530225 unsigned long flags;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +0530226 int i;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200227
228 if (ath_startrecv(sc) != 0) {
229 ath_err(common, "Unable to restart recv logic\n");
230 return false;
231 }
232
233 ath9k_cmn_update_txpow(ah, sc->curtxpow,
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530234 sc->cur_chan->txpower, &sc->curtxpow);
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530235
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100236 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530237 ath9k_calculate_summary_state(sc, sc->cur_chan);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200238
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530239 if (!sc->cur_chan->offchannel && start) {
Felix Fietkau8d7e09d2014-06-11 16:18:01 +0530240 /* restore per chanctx TSF timer */
241 if (sc->cur_chan->tsf_val) {
242 u32 offset;
243
244 offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts,
245 NULL);
246 ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset);
247 }
248
249
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100250 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
Sujith Manoharan196fb862012-06-04 20:24:13 +0530251 goto work;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200252
Sujith Manoharan196fb862012-06-04 20:24:13 +0530253 if (ah->opmode == NL80211_IFTYPE_STATION &&
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100254 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
Sujith Manoharan196fb862012-06-04 20:24:13 +0530255 spin_lock_irqsave(&sc->sc_pm_lock, flags);
256 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
257 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Sujith Manoharana6768282013-05-06 10:09:03 +0530258 } else {
259 ath9k_set_beacon(sc);
Sujith Manoharan196fb862012-06-04 20:24:13 +0530260 }
261 work:
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530262 ath_restart_work(sc);
Felix Fietkau04535312014-06-11 16:17:51 +0530263 ath_txq_schedule_all(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200264 }
265
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530266 sc->gtt_cnt = 0;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530267
268 ath9k_hw_set_interrupts(ah);
269 ath9k_hw_enable_interrupts(ah);
270
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +0530271 if (!ath9k_use_chanctx)
272 ieee80211_wake_queues(sc->hw);
273 else {
274 if (sc->cur_chan == &sc->offchannel.chan)
275 ieee80211_wake_queue(sc->hw,
276 sc->hw->offchannel_tx_hw_queue);
277 else {
278 for (i = 0; i < IEEE80211_NUM_ACS; i++)
279 ieee80211_wake_queue(sc->hw,
280 sc->cur_chan->hw_queue_base + i);
281 }
282 if (ah->opmode == NL80211_IFTYPE_AP)
283 ieee80211_wake_queue(sc->hw, sc->hw->queues - 2);
284 }
Felix Fietkau9adcf442011-09-03 01:40:26 +0200285
Felix Fietkaud463af42014-04-06 00:37:03 +0200286 ath9k_p2p_ps_timer(sc);
287
Felix Fietkau9adcf442011-09-03 01:40:26 +0200288 return true;
289}
290
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530291int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
Felix Fietkau9adcf442011-09-03 01:40:26 +0200292{
293 struct ath_hw *ah = sc->sc_ah;
294 struct ath_common *common = ath9k_hw_common(ah);
295 struct ath9k_hw_cal_data *caldata = NULL;
296 bool fastcc = true;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200297 int r;
298
299 __ath_cancel_work(sc);
300
Felix Fietkau4668cce2013-01-14 16:56:46 +0100301 tasklet_disable(&sc->intr_tq);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200302 spin_lock_bh(&sc->sc_pcu_lock);
303
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530304 if (!sc->cur_chan->offchannel) {
Felix Fietkau9adcf442011-09-03 01:40:26 +0200305 fastcc = false;
Felix Fietkaub01459e2014-06-11 16:17:59 +0530306 caldata = &sc->cur_chan->caldata;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200307 }
308
309 if (!hchan) {
310 fastcc = false;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200311 hchan = ah->curchan;
312 }
313
John W. Linville9ebea382013-01-28 13:54:03 -0500314 if (!ath_prepare_reset(sc))
Felix Fietkau9adcf442011-09-03 01:40:26 +0200315 fastcc = false;
316
Rajkumar Manoharand6067f02014-06-20 22:47:49 +0530317 spin_lock_bh(&sc->chan_lock);
318 sc->cur_chandef = sc->cur_chan->chandef;
319 spin_unlock_bh(&sc->chan_lock);
Felix Fietkaubff11762014-06-11 16:17:52 +0530320
Joe Perchesd2182b62011-12-15 14:55:53 -0800321 ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
Sujith Manoharanfeced202012-01-30 14:21:42 +0530322 hchan->channel, IS_CHAN_HT40(hchan), fastcc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200323
324 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
325 if (r) {
326 ath_err(common,
327 "Unable to reset channel, reset status %d\n", r);
Robert Shadef50b1cd2013-04-02 19:52:45 -0400328
329 ath9k_hw_enable_interrupts(ah);
330 ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
331
Felix Fietkau9adcf442011-09-03 01:40:26 +0200332 goto out;
333 }
334
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530335 if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530336 sc->cur_chan->offchannel)
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530337 ath9k_mci_set_txpower(sc, true, false);
338
Felix Fietkau9adcf442011-09-03 01:40:26 +0200339 if (!ath_complete_reset(sc, true))
340 r = -EIO;
341
342out:
343 spin_unlock_bh(&sc->sc_pcu_lock);
Felix Fietkau4668cce2013-01-14 16:56:46 +0100344 tasklet_enable(&sc->intr_tq);
345
Felix Fietkau9adcf442011-09-03 01:40:26 +0200346 return r;
347}
348
Ben Greear7e1e3862011-11-03 11:33:13 -0700349static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
350 struct ieee80211_vif *vif)
Sujithff37e332008-11-24 12:07:55 +0530351{
352 struct ath_node *an;
Sujithff37e332008-11-24 12:07:55 +0530353 an = (struct ath_node *)sta->drv_priv;
354
Sujith Manoharana145daf2012-11-28 15:08:54 +0530355 an->sc = sc;
Ben Greear7f010c92011-01-09 23:11:49 -0800356 an->sta = sta;
Ben Greear7e1e3862011-11-03 11:33:13 -0700357 an->vif = vif;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +0530358 memset(&an->key_idx, 0, sizeof(an->key_idx));
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530359
Sujith Manoharandd5ee592013-02-04 15:38:23 +0530360 ath_tx_node_init(sc, an);
Sujithff37e332008-11-24 12:07:55 +0530361}
362
363static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
364{
365 struct ath_node *an = (struct ath_node *)sta->drv_priv;
Sujith Manoharandd5ee592013-02-04 15:38:23 +0530366 ath_tx_node_cleanup(sc, an);
Sujithff37e332008-11-24 12:07:55 +0530367}
368
Sujith55624202010-01-08 10:36:02 +0530369void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530370{
371 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700372 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700373 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530374 enum ath_reset_type type;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530375 unsigned long flags;
Sujith17d79042009-02-09 13:27:03 +0530376 u32 status = sc->intrstatus;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400377 u32 rxmask;
Sujithff37e332008-11-24 12:07:55 +0530378
Felix Fietkaue3927002011-09-14 21:23:01 +0200379 ath9k_ps_wakeup(sc);
380 spin_lock(&sc->sc_pcu_lock);
381
Sujith Manoharan6549a862013-12-24 10:44:24 +0530382 if (status & ATH9K_INT_FATAL) {
383 type = RESET_TYPE_FATAL_INT;
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530384 ath9k_queue_reset(sc, type);
Sujith Manoharanc6cc47b2013-09-16 10:37:00 +0530385
386 /*
387 * Increment the ref. counter here so that
388 * interrupts are enabled in the reset routine.
389 */
390 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100391 ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
Felix Fietkaue3927002011-09-14 21:23:01 +0200392 goto out;
Sujithff37e332008-11-24 12:07:55 +0530393 }
394
Sujith Manoharan6549a862013-12-24 10:44:24 +0530395 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
396 (status & ATH9K_INT_BB_WATCHDOG)) {
Sujith Manoharan0c759972013-12-24 10:44:26 +0530397 spin_lock(&common->cc_lock);
398 ath_hw_cycle_counters_update(common);
399 ar9003_hw_bb_watchdog_dbg_info(ah);
400 spin_unlock(&common->cc_lock);
401
Sujith Manoharan6549a862013-12-24 10:44:24 +0530402 if (ar9003_hw_bb_watchdog_check(ah)) {
403 type = RESET_TYPE_BB_WATCHDOG;
404 ath9k_queue_reset(sc, type);
405
406 /*
407 * Increment the ref. counter here so that
408 * interrupts are enabled in the reset routine.
409 */
410 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100411 ath_dbg(common, RESET,
Sujith Manoharan6549a862013-12-24 10:44:24 +0530412 "BB_WATCHDOG: Skipping interrupts\n");
413 goto out;
414 }
415 }
416
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530417 if (status & ATH9K_INT_GTT) {
418 sc->gtt_cnt++;
419
420 if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
421 type = RESET_TYPE_TX_GTT;
422 ath9k_queue_reset(sc, type);
423 atomic_inc(&ah->intr_ref_cnt);
Felix Fietkauaffad452014-02-22 14:52:49 +0100424 ath_dbg(common, RESET,
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530425 "GTT: Skipping interrupts\n");
426 goto out;
427 }
428 }
429
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530430 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530431 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
432 /*
433 * TSF sync does not look correct; remain awake to sync with
434 * the next Beacon.
435 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800436 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
Rajkumar Manoharane8fe7332011-08-05 18:59:41 +0530437 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530438 }
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530439 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530440
Felix Fietkaub5c804752010-04-15 17:38:48 -0400441 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
442 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
443 ATH9K_INT_RXORN);
444 else
445 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
446
447 if (status & rxmask) {
Felix Fietkaub5c804752010-04-15 17:38:48 -0400448 /* Check for high priority Rx first */
449 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
450 (status & ATH9K_INT_RXHP))
451 ath_rx_tasklet(sc, 0, true);
452
453 ath_rx_tasklet(sc, 0, false);
Sujith063d8be2009-03-30 15:28:49 +0530454 }
455
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400456 if (status & ATH9K_INT_TX) {
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530457 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
458 /*
459 * For EDMA chips, TX completion is enabled for the
460 * beacon queue, so if a beacon has been transmitted
461 * successfully after a GTT interrupt, the GTT counter
462 * gets reset to zero here.
463 */
Sujith Manoharan3b745c72014-01-20 13:25:28 +0530464 sc->gtt_cnt = 0;
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530465
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400466 ath_tx_edma_tasklet(sc);
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530467 } else {
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400468 ath_tx_tasklet(sc);
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530469 }
Felix Fietkau10e23182013-11-11 22:23:35 +0100470
471 wake_up(&sc->tx_wait);
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400472 }
Sujith063d8be2009-03-30 15:28:49 +0530473
Felix Fietkauc67ce332013-12-14 18:03:38 +0100474 if (status & ATH9K_INT_GENTIMER)
475 ath_gen_timer_isr(sc->sc_ah);
476
Sujith Manoharan56ca0db2012-02-22 12:40:32 +0530477 ath9k_btcoex_handle_interrupt(sc, status);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530478
Sujithff37e332008-11-24 12:07:55 +0530479 /* re-enable hardware interrupt */
Felix Fietkau4df30712010-11-08 20:54:47 +0100480 ath9k_hw_enable_interrupts(ah);
Sujith Manoharanc6cc47b2013-09-16 10:37:00 +0530481out:
Senthil Balasubramanian52671e42010-12-23 21:06:57 +0530482 spin_unlock(&sc->sc_pcu_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400483 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530484}
485
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100486irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530487{
Sujith063d8be2009-03-30 15:28:49 +0530488#define SCHED_INTR ( \
489 ATH9K_INT_FATAL | \
Rajkumar Manoharana4d86d92011-05-20 17:52:10 +0530490 ATH9K_INT_BB_WATCHDOG | \
Sujith063d8be2009-03-30 15:28:49 +0530491 ATH9K_INT_RXORN | \
492 ATH9K_INT_RXEOL | \
493 ATH9K_INT_RX | \
Felix Fietkaub5c804752010-04-15 17:38:48 -0400494 ATH9K_INT_RXLP | \
495 ATH9K_INT_RXHP | \
Sujith063d8be2009-03-30 15:28:49 +0530496 ATH9K_INT_TX | \
497 ATH9K_INT_BMISS | \
498 ATH9K_INT_CST | \
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530499 ATH9K_INT_GTT | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530500 ATH9K_INT_TSFOOR | \
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530501 ATH9K_INT_GENTIMER | \
502 ATH9K_INT_MCI)
Sujith063d8be2009-03-30 15:28:49 +0530503
Sujithff37e332008-11-24 12:07:55 +0530504 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530505 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100506 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530507 enum ath9k_int status;
Sujith Manoharan78c8a952013-12-28 09:47:15 +0530508 u32 sync_cause = 0;
Sujithff37e332008-11-24 12:07:55 +0530509 bool sched = false;
510
Sujith063d8be2009-03-30 15:28:49 +0530511 /*
512 * The hardware is not ready/present, don't
513 * touch anything. Note this can happen early
514 * on if the IRQ is shared.
515 */
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100516 if (test_bit(ATH_OP_INVALID, &common->op_flags))
Sujith063d8be2009-03-30 15:28:49 +0530517 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530518
Sujith063d8be2009-03-30 15:28:49 +0530519 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530520
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400521 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530522 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530523
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100524 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
Felix Fietkauf41a9b32012-08-08 16:25:03 +0200525 ath9k_hw_kill_interrupts(ah);
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530526 return IRQ_HANDLED;
Felix Fietkauf41a9b32012-08-08 16:25:03 +0200527 }
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530528
Sujith063d8be2009-03-30 15:28:49 +0530529 /*
530 * Figure out the reason(s) for the interrupt. Note
531 * that the hal returns a pseudo-ISR that may include
532 * bits we haven't explicitly enabled so we mask the
533 * value to insure we only process bits we requested.
534 */
Felix Fietkau6a4d05d2013-12-19 18:01:48 +0100535 ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
536 ath9k_debug_sync_cause(sc, sync_cause);
Pavel Roskin30691682010-03-31 18:05:31 -0400537 status &= ah->imask; /* discard unasked-for bits */
Sujith063d8be2009-03-30 15:28:49 +0530538
539 /*
540 * If there are no status bits set, then this interrupt was not
541 * for me (should have been caught above).
542 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400543 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530544 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530545
546 /* Cache the status */
547 sc->intrstatus = status;
548
549 if (status & SCHED_INTR)
550 sched = true;
551
552 /*
553 * If a FATAL or RXORN interrupt is received, we have to reset the
554 * chip immediately.
555 */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400556 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
557 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
Sujith063d8be2009-03-30 15:28:49 +0530558 goto chip_reset;
559
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530560 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
Sujith Manoharan0c759972013-12-24 10:44:26 +0530561 (status & ATH9K_INT_BB_WATCHDOG))
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400562 goto chip_reset;
Sujith Manoharane60001e2013-10-28 12:22:04 +0530563
564#ifdef CONFIG_ATH9K_WOW
Rajkumar Manoharanca90ef42012-11-20 18:29:59 +0530565 if (status & ATH9K_INT_BMISS) {
566 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
Rajkumar Manoharanca90ef42012-11-20 18:29:59 +0530567 atomic_inc(&sc->wow_got_bmiss_intr);
568 atomic_dec(&sc->wow_sleep_proc_intr);
569 }
570 }
571#endif
Sujith Manoharane60001e2013-10-28 12:22:04 +0530572
Sujith063d8be2009-03-30 15:28:49 +0530573 if (status & ATH9K_INT_SWBA)
574 tasklet_schedule(&sc->bcon_tasklet);
575
576 if (status & ATH9K_INT_TXURN)
577 ath9k_hw_updatetxtriglevel(ah, true);
578
Rajkumar Manoharan0682c9b2011-08-13 10:28:09 +0530579 if (status & ATH9K_INT_RXEOL) {
580 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +0200581 ath9k_hw_set_interrupts(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400582 }
583
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400584 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
585 if (status & ATH9K_INT_TIM_TIMER) {
Luis R. Rodriguezff9f0b62010-12-07 15:13:22 -0800586 if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
587 goto chip_reset;
Sujith063d8be2009-03-30 15:28:49 +0530588 /* Clear RxAbort bit so that we can
589 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700590 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530591 spin_lock(&sc->sc_pm_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400592 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530593 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530594 spin_unlock(&sc->sc_pm_lock);
Sujith063d8be2009-03-30 15:28:49 +0530595 }
Sujith063d8be2009-03-30 15:28:49 +0530596
597chip_reset:
598
Sujith817e11d2008-12-07 21:42:44 +0530599 ath_debug_stat_interrupt(sc, status);
600
Sujithff37e332008-11-24 12:07:55 +0530601 if (sched) {
Felix Fietkau4df30712010-11-08 20:54:47 +0100602 /* turn off every interrupt */
603 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530604 tasklet_schedule(&sc->intr_tq);
605 }
606
607 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530608
609#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530610}
611
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530612int ath_reset(struct ath_softc *sc)
Sujithff37e332008-11-24 12:07:55 +0530613{
Felix Fietkauec303262013-10-05 14:09:30 +0200614 int r;
Sujithff37e332008-11-24 12:07:55 +0530615
Felix Fietkau783cd012011-01-21 18:52:38 +0100616 ath9k_ps_wakeup(sc);
Felix Fietkau13815592013-01-20 18:51:53 +0100617 r = ath_reset_internal(sc, NULL);
Felix Fietkau783cd012011-01-21 18:52:38 +0100618 ath9k_ps_restore(sc);
Sujith2ab81d42009-12-14 16:34:56 +0530619
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800620 return r;
Sujithff37e332008-11-24 12:07:55 +0530621}
622
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530623void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
624{
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100625 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530626#ifdef CONFIG_ATH9K_DEBUGFS
627 RESET_STAT_INC(sc, type);
628#endif
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100629 set_bit(ATH_OP_HW_RESET, &common->op_flags);
Rajkumar Manoharan124b9792012-07-17 17:16:42 +0530630 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
631}
632
Felix Fietkau236de512011-09-03 01:40:25 +0200633void ath_reset_work(struct work_struct *work)
634{
635 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
636
Felix Fietkau13815592013-01-20 18:51:53 +0100637 ath_reset(sc);
Felix Fietkau236de512011-09-03 01:40:25 +0200638}
639
Sujithff37e332008-11-24 12:07:55 +0530640/**********************/
641/* mac80211 callbacks */
642/**********************/
643
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644static int ath9k_start(struct ieee80211_hw *hw)
645{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100646 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700647 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700648 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau39305632014-06-11 16:17:57 +0530649 struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan;
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530650 struct ath_chanctx *ctx = sc->cur_chan;
Sujithff37e332008-11-24 12:07:55 +0530651 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530652 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700653
Joe Perchesd2182b62011-12-15 14:55:53 -0800654 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -0800655 "Starting driver with initial channel: %d MHz\n",
656 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700657
Felix Fietkauf62d8162011-03-25 17:43:41 +0100658 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +0530659 mutex_lock(&sc->mutex);
660
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530661 init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
Felix Fietkaubff11762014-06-11 16:17:52 +0530662 sc->cur_chandef = hw->conf.chandef;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700663
Sujithff37e332008-11-24 12:07:55 +0530664 /* Reset SERDES registers */
Stanislaw Gruszka84c87dc2011-08-05 13:10:32 +0200665 ath9k_hw_configpcipowersave(ah, false);
Sujithff37e332008-11-24 12:07:55 +0530666
667 /*
668 * The basic interface to setting the hardware in a good
669 * state is ``reset''. On return the hardware is known to
670 * be powered up and with interrupts disabled. This must
671 * be followed by initialization of the appropriate bits
672 * and then setup of the interrupt mask.
673 */
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700674 spin_lock_bh(&sc->sc_pcu_lock);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100675
676 atomic_set(&ah->intr_ref_cnt, -1);
677
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200678 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800679 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800680 ath_err(common,
681 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
682 r, curchan->center_freq);
Felix Fietkauceb26a62012-10-03 21:07:51 +0200683 ah->reset_power_on = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684 }
Sujithff37e332008-11-24 12:07:55 +0530685
Sujithff37e332008-11-24 12:07:55 +0530686 /* Setup our intr mask. */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400687 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
688 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
689 ATH9K_INT_GLOBAL;
690
691 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400692 ah->imask |= ATH9K_INT_RXHP |
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530693 ATH9K_INT_RXLP;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400694 else
695 ah->imask |= ATH9K_INT_RX;
Sujithff37e332008-11-24 12:07:55 +0530696
Sujith Manoharana6bb8602013-12-24 10:44:22 +0530697 if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
698 ah->imask |= ATH9K_INT_BB_WATCHDOG;
699
Sujith Manoharan071aa9a2014-01-13 13:55:11 +0530700 /*
701 * Enable GTT interrupts only for AR9003/AR9004 chips
702 * for now.
703 */
704 if (AR_SREV_9300_20_OR_LATER(ah))
705 ah->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +0530706
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700707 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Pavel Roskin30691682010-03-31 18:05:31 -0400708 ah->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +0530709
Sujith Manoharane270e772012-06-04 16:27:19 +0530710 ath_mci_enable(sc);
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530711
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100712 clear_bit(ATH_OP_INVALID, &common->op_flags);
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530713 sc->sc_ah->is_monitoring = false;
Sujithff37e332008-11-24 12:07:55 +0530714
Felix Fietkauceb26a62012-10-03 21:07:51 +0200715 if (!ath_complete_reset(sc, false))
716 ah->reset_power_on = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700717
Felix Fietkauc0c11742011-11-16 13:08:41 +0100718 if (ah->led_pin >= 0) {
719 ath9k_hw_cfg_output(ah, ah->led_pin,
720 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
721 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
722 }
723
724 /*
725 * Reset key cache to sane defaults (all entries cleared) instead of
726 * semi-random values after suspend/resume.
727 */
728 ath9k_cmn_init_crypto(sc->sc_ah);
729
Felix Fietkaua35051c2013-12-14 18:03:45 +0100730 ath9k_hw_reset_tsf(ah);
731
Felix Fietkau9adcf442011-09-03 01:40:26 +0200732 spin_unlock_bh(&sc->sc_pcu_lock);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -0400733
Sujith141b38b2009-02-04 08:10:07 +0530734 mutex_unlock(&sc->mutex);
735
Felix Fietkauf62d8162011-03-25 17:43:41 +0100736 ath9k_ps_restore(sc);
737
Felix Fietkauceb26a62012-10-03 21:07:51 +0200738 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700739}
740
Thomas Huehn36323f82012-07-23 21:33:42 +0200741static void ath9k_tx(struct ieee80211_hw *hw,
742 struct ieee80211_tx_control *control,
743 struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100745 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700746 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +0530747 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +0100748 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530749 unsigned long flags;
Sujith528f0c62008-10-29 10:14:26 +0530750
Gabor Juhos96148322009-07-24 17:27:21 +0200751 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +0300752 /*
753 * mac80211 does not set PM field for normal data frames, so we
754 * need to update that based on the current PS mode.
755 */
756 if (ieee80211_is_data(hdr->frame_control) &&
757 !ieee80211_is_nullfunc(hdr->frame_control) &&
758 !ieee80211_has_pm(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800759 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800760 "Add PM=1 for a TX frame while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +0300761 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
762 }
763 }
764
Sujith Manoharanad128862012-04-24 10:23:20 +0530765 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300766 /*
767 * We are using PS-Poll and mac80211 can request TX while in
768 * power save mode. Need to wake up hardware for the TX to be
769 * completed and if needed, also for RX of buffered frames.
770 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300771 ath9k_ps_wakeup(sc);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530772 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -0700773 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
774 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300775 if (ieee80211_is_pspoll(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800776 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800777 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +0530778 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300779 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -0800780 ath_dbg(common, PS, "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +0530781 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300782 }
783 /*
784 * The actual restore operation will happen only after
Sujith Manoharanad128862012-04-24 10:23:20 +0530785 * the ps_flags bit is cleared. We are just dropping
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300786 * the ps_usecount here.
787 */
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530788 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300789 ath9k_ps_restore(sc);
790 }
791
Sujith Manoharanad128862012-04-24 10:23:20 +0530792 /*
793 * Cannot tx while the hardware is in full sleep, it first needs a full
794 * chip reset to recover from that
795 */
796 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
797 ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
798 goto exit;
799 }
800
Sujith528f0c62008-10-29 10:14:26 +0530801 memset(&txctl, 0, sizeof(struct ath_tx_control));
Felix Fietkau066dae92010-11-07 14:59:39 +0100802 txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
Thomas Huehn36323f82012-07-23 21:33:42 +0200803 txctl.sta = control->sta;
Sujith528f0c62008-10-29 10:14:26 +0530804
Joe Perchesd2182b62011-12-15 14:55:53 -0800805 ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200807 if (ath_tx_start(hw, skb, &txctl) != 0) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800808 ath_dbg(common, XMIT, "TX failed\n");
Ben Greeara5a0bca2012-04-03 09:16:55 -0700809 TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
Sujith528f0c62008-10-29 10:14:26 +0530810 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700811 }
812
Johannes Berg7bb45682011-02-24 14:42:06 +0100813 return;
Sujith528f0c62008-10-29 10:14:26 +0530814exit:
Felix Fietkau249ee722012-10-03 21:07:52 +0200815 ieee80211_free_txskb(hw, skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816}
817
818static void ath9k_stop(struct ieee80211_hw *hw)
819{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100820 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700821 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700822 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100823 bool prev_idle;
Sujith9c84b792008-10-29 10:17:13 +0530824
Felix Fietkaubff11762014-06-11 16:17:52 +0530825 cancel_work_sync(&sc->chanctx_work);
Sujith4c483812009-08-18 10:51:52 +0530826 mutex_lock(&sc->mutex);
827
Felix Fietkau9adcf442011-09-03 01:40:26 +0200828 ath_cancel_work(sc);
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -0700829
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100830 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800831 ath_dbg(common, ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +0530832 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +0530833 return;
834 }
835
Sujith3867cf62009-12-23 20:03:27 -0500836 /* Ensure HW is awake when we try to shut it down. */
837 ath9k_ps_wakeup(sc);
838
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700839 spin_lock_bh(&sc->sc_pcu_lock);
840
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100841 /* prevent tasklets to enable interrupts once we disable them */
842 ah->imask &= ~ATH9K_INT_GLOBAL;
843
Sujithff37e332008-11-24 12:07:55 +0530844 /* make sure h/w will not generate any interrupt
845 * before setting the invalid flag. */
Felix Fietkau4df30712010-11-08 20:54:47 +0100846 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530847
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700848 spin_unlock_bh(&sc->sc_pcu_lock);
849
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100850 /* we can now sync irq and kill any running tasklets, since we already
851 * disabled interrupts and not holding a spin lock */
852 synchronize_irq(sc->irq);
853 tasklet_kill(&sc->intr_tq);
854 tasklet_kill(&sc->bcon_tasklet);
855
Felix Fietkauc0c11742011-11-16 13:08:41 +0100856 prev_idle = sc->ps_idle;
857 sc->ps_idle = true;
858
859 spin_lock_bh(&sc->sc_pcu_lock);
860
861 if (ah->led_pin >= 0) {
862 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
863 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
864 }
865
John W. Linville9ebea382013-01-28 13:54:03 -0500866 ath_prepare_reset(sc);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100867
868 if (sc->rx.frag) {
869 dev_kfree_skb_any(sc->rx.frag);
870 sc->rx.frag = NULL;
871 }
872
873 if (!ah->curchan)
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530874 ah->curchan = ath9k_cmn_get_channel(hw, ah,
875 &sc->cur_chan->chandef);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100876
877 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
878 ath9k_hw_phy_disable(ah);
879
880 ath9k_hw_configpcipowersave(ah, true);
881
882 spin_unlock_bh(&sc->sc_pcu_lock);
883
Sujith3867cf62009-12-23 20:03:27 -0500884 ath9k_ps_restore(sc);
885
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100886 set_bit(ATH_OP_INVALID, &common->op_flags);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100887 sc->ps_idle = prev_idle;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888
Sujith141b38b2009-02-04 08:10:07 +0530889 mutex_unlock(&sc->mutex);
890
Joe Perchesd2182b62011-12-15 14:55:53 -0800891 ath_dbg(common, CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700892}
893
Felix Fietkauc648ecb2013-10-11 23:31:00 +0200894static bool ath9k_uses_beacons(int type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700895{
Ben Greear48014162011-01-15 19:13:48 +0000896 switch (type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200897 case NL80211_IFTYPE_AP:
Ben Greear48014162011-01-15 19:13:48 +0000898 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -0400899 case NL80211_IFTYPE_MESH_POINT:
Ben Greear48014162011-01-15 19:13:48 +0000900 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700901 default:
Ben Greear48014162011-01-15 19:13:48 +0000902 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700903 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700904}
905
Ben Greear48014162011-01-15 19:13:48 +0000906static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
907{
908 struct ath9k_vif_iter_data *iter_data = data;
909 int i;
910
Felix Fietkauab11bb22013-04-16 12:51:57 +0200911 if (iter_data->has_hw_macaddr) {
Ben Greear48014162011-01-15 19:13:48 +0000912 for (i = 0; i < ETH_ALEN; i++)
913 iter_data->mask[i] &=
914 ~(iter_data->hw_macaddr[i] ^ mac[i]);
Felix Fietkauab11bb22013-04-16 12:51:57 +0200915 } else {
916 memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
917 iter_data->has_hw_macaddr = true;
918 }
Ben Greear48014162011-01-15 19:13:48 +0000919
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530920 if (!vif->bss_conf.use_short_slot)
921 iter_data->slottime = ATH9K_SLOT_TIME_20;
922
Ben Greear48014162011-01-15 19:13:48 +0000923 switch (vif->type) {
924 case NL80211_IFTYPE_AP:
925 iter_data->naps++;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530926 if (vif->bss_conf.enable_beacon)
927 iter_data->beacons = true;
Ben Greear48014162011-01-15 19:13:48 +0000928 break;
929 case NL80211_IFTYPE_STATION:
930 iter_data->nstations++;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530931 if (vif->bss_conf.assoc && !iter_data->primary_sta)
932 iter_data->primary_sta = vif;
Ben Greear48014162011-01-15 19:13:48 +0000933 break;
934 case NL80211_IFTYPE_ADHOC:
935 iter_data->nadhocs++;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530936 if (vif->bss_conf.enable_beacon)
937 iter_data->beacons = true;
Ben Greear48014162011-01-15 19:13:48 +0000938 break;
939 case NL80211_IFTYPE_MESH_POINT:
940 iter_data->nmeshes++;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530941 if (vif->bss_conf.enable_beacon)
942 iter_data->beacons = true;
Ben Greear48014162011-01-15 19:13:48 +0000943 break;
944 case NL80211_IFTYPE_WDS:
945 iter_data->nwds++;
946 break;
947 default:
Ben Greear48014162011-01-15 19:13:48 +0000948 break;
949 }
950}
951
952/* Called with sc->mutex held. */
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530953void ath9k_calculate_iter_data(struct ath_softc *sc,
954 struct ath_chanctx *ctx,
Ben Greear48014162011-01-15 19:13:48 +0000955 struct ath9k_vif_iter_data *iter_data)
956{
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530957 struct ath_vif *avp;
Ben Greear48014162011-01-15 19:13:48 +0000958
959 /*
Mathy Vanhoef657eb172013-11-28 12:21:45 +0100960 * Pick the MAC address of the first interface as the new hardware
961 * MAC address. The hardware will use it together with the BSSID mask
962 * when matching addresses.
Ben Greear48014162011-01-15 19:13:48 +0000963 */
964 memset(iter_data, 0, sizeof(*iter_data));
Ben Greear48014162011-01-15 19:13:48 +0000965 memset(&iter_data->mask, 0xff, ETH_ALEN);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530966 iter_data->slottime = ATH9K_SLOT_TIME_9;
Ben Greear48014162011-01-15 19:13:48 +0000967
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530968 list_for_each_entry(avp, &ctx->vifs, list)
969 ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif);
Ben Greear48014162011-01-15 19:13:48 +0000970
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530971 if (ctx == &sc->offchannel.chan) {
972 struct ieee80211_vif *vif;
Felix Fietkauab11bb22013-04-16 12:51:57 +0200973
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +0530974 if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START)
975 vif = sc->offchannel.scan_vif;
976 else
977 vif = sc->offchannel.roc_vif;
978
979 if (vif)
980 ath9k_vif_iter(iter_data, vif->addr, vif);
981 iter_data->beacons = false;
982 }
983}
984
985static void ath9k_set_assoc_state(struct ath_softc *sc,
986 struct ieee80211_vif *vif, bool changed)
987{
988 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
989 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
990 unsigned long flags;
991
992 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
993 /* Set the AID, BSSID and do beacon-sync only when
994 * the HW opmode is STATION.
995 *
996 * But the primary bit is set above in any case.
997 */
998 if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
999 return;
1000
1001 ether_addr_copy(common->curbssid, bss_conf->bssid);
1002 common->curaid = bss_conf->aid;
1003 ath9k_hw_write_associd(sc->sc_ah);
1004
1005 if (changed) {
1006 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
1007 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
1008
1009 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1010 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
1011 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1012 }
1013
1014 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1015 ath9k_mci_update_wlan_channels(sc, false);
1016
1017 ath_dbg(common, CONFIG,
1018 "Primary Station interface: %pM, BSSID: %pM\n",
1019 vif->addr, common->curbssid);
Ben Greear48014162011-01-15 19:13:48 +00001020}
1021
1022/* Called with sc->mutex held. */
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301023void ath9k_calculate_summary_state(struct ath_softc *sc,
1024 struct ath_chanctx *ctx)
Ben Greear48014162011-01-15 19:13:48 +00001025{
Ben Greear48014162011-01-15 19:13:48 +00001026 struct ath_hw *ah = sc->sc_ah;
1027 struct ath_common *common = ath9k_hw_common(ah);
1028 struct ath9k_vif_iter_data iter_data;
1029
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301030 ath_chanctx_check_active(sc, ctx);
1031
1032 if (ctx != sc->cur_chan)
1033 return;
1034
1035 ath9k_ps_wakeup(sc);
1036 ath9k_calculate_iter_data(sc, ctx, &iter_data);
1037
1038 if (iter_data.has_hw_macaddr)
1039 ether_addr_copy(common->macaddr, iter_data.hw_macaddr);
Ben Greear48014162011-01-15 19:13:48 +00001040
Ben Greear48014162011-01-15 19:13:48 +00001041 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
1042 ath_hw_setbssidmask(common);
1043
Ben Greear48014162011-01-15 19:13:48 +00001044 if (iter_data.naps > 0) {
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05301045 ath9k_hw_set_tsfadjust(ah, true);
Ben Greear48014162011-01-15 19:13:48 +00001046 ah->opmode = NL80211_IFTYPE_AP;
1047 } else {
Sujith Manoharan60ca9f82012-07-17 17:15:37 +05301048 ath9k_hw_set_tsfadjust(ah, false);
Ben Greear48014162011-01-15 19:13:48 +00001049
Javier Cardonafd5999c2011-05-03 16:57:19 -07001050 if (iter_data.nmeshes)
1051 ah->opmode = NL80211_IFTYPE_MESH_POINT;
1052 else if (iter_data.nwds)
Ben Greear48014162011-01-15 19:13:48 +00001053 ah->opmode = NL80211_IFTYPE_AP;
1054 else if (iter_data.nadhocs)
1055 ah->opmode = NL80211_IFTYPE_ADHOC;
1056 else
1057 ah->opmode = NL80211_IFTYPE_STATION;
1058 }
1059
Sujith Manoharandf35d292012-07-17 17:15:43 +05301060 ath9k_hw_setopmode(ah);
1061
Felix Fietkau748299f2014-06-11 16:18:04 +05301062 ctx->switch_after_beacon = false;
Felix Fietkau198823f2012-06-15 15:25:25 +02001063 if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
Ben Greear48014162011-01-15 19:13:48 +00001064 ah->imask |= ATH9K_INT_TSFOOR;
Felix Fietkau748299f2014-06-11 16:18:04 +05301065 else {
Ben Greear48014162011-01-15 19:13:48 +00001066 ah->imask &= ~ATH9K_INT_TSFOOR;
Felix Fietkau748299f2014-06-11 16:18:04 +05301067 if (iter_data.naps == 1 && iter_data.beacons)
1068 ctx->switch_after_beacon = true;
1069 }
Ben Greear48014162011-01-15 19:13:48 +00001070
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301071 ah->imask &= ~ATH9K_INT_SWBA;
1072 if (ah->opmode == NL80211_IFTYPE_STATION) {
1073 bool changed = (iter_data.primary_sta != ctx->primary_sta);
1074
1075 iter_data.beacons = true;
1076 if (iter_data.primary_sta) {
1077 ath9k_set_assoc_state(sc, iter_data.primary_sta,
1078 changed);
1079 if (!ctx->primary_sta ||
1080 !ctx->primary_sta->bss_conf.assoc)
1081 ctx->primary_sta = iter_data.primary_sta;
1082 } else {
1083 ctx->primary_sta = NULL;
1084 memset(common->curbssid, 0, ETH_ALEN);
1085 common->curaid = 0;
1086 ath9k_hw_write_associd(sc->sc_ah);
1087 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1088 ath9k_mci_update_wlan_channels(sc, true);
1089 }
1090 } else if (iter_data.beacons) {
1091 ah->imask |= ATH9K_INT_SWBA;
1092 }
Felix Fietkau72d874c2011-10-08 20:06:19 +02001093 ath9k_hw_set_interrupts(ah);
Sujith Manoharan6dcc3442012-07-17 17:16:36 +05301094
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301095 if (iter_data.beacons)
1096 set_bit(ATH_OP_BEACONS, &common->op_flags);
1097 else
1098 clear_bit(ATH_OP_BEACONS, &common->op_flags);
1099
1100 if (ah->slottime != iter_data.slottime) {
1101 ah->slottime = iter_data.slottime;
1102 ath9k_hw_init_global_settings(ah);
Sujith Manoharan6dcc3442012-07-17 17:16:36 +05301103 }
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301104
1105 if (iter_data.primary_sta)
1106 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1107 else
1108 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1109
1110 ctx->primary_sta = iter_data.primary_sta;
1111
1112 ath9k_ps_restore(sc);
Ben Greear48014162011-01-15 19:13:48 +00001113}
1114
Ben Greear48014162011-01-15 19:13:48 +00001115static int ath9k_add_interface(struct ieee80211_hw *hw,
1116 struct ieee80211_vif *vif)
1117{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001118 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +00001119 struct ath_hw *ah = sc->sc_ah;
1120 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001121 struct ath_vif *avp = (void *)vif->drv_priv;
1122 struct ath_node *an = &avp->mcast_node;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301123 int i;
Ben Greear48014162011-01-15 19:13:48 +00001124
1125 mutex_lock(&sc->mutex);
1126
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001127 if (config_enabled(CONFIG_ATH9K_TX99)) {
1128 if (sc->nvifs >= 1) {
1129 mutex_unlock(&sc->mutex);
1130 return -EOPNOTSUPP;
1131 }
1132 sc->tx99_vif = vif;
1133 }
1134
Joe Perchesd2182b62011-12-15 14:55:53 -08001135 ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
Ben Greear48014162011-01-15 19:13:48 +00001136 sc->nvifs++;
1137
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301138 if (ath9k_uses_beacons(vif->type))
1139 ath9k_beacon_assign_slot(sc, vif);
1140
Felix Fietkaud463af42014-04-06 00:37:03 +02001141 avp->vif = vif;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301142 if (!ath9k_use_chanctx) {
Felix Fietkau39305632014-06-11 16:17:57 +05301143 avp->chanctx = sc->cur_chan;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301144 list_add_tail(&avp->list, &avp->chanctx->vifs);
1145 }
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301146 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1147 vif->hw_queue[i] = i;
1148 if (vif->type == NL80211_IFTYPE_AP)
1149 vif->cab_queue = hw->queues - 2;
1150 else
1151 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
Felix Fietkau04535312014-06-11 16:17:51 +05301152
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001153 an->sc = sc;
1154 an->sta = NULL;
1155 an->vif = vif;
1156 an->no_ps_filter = true;
1157 ath_tx_node_init(sc, an);
1158
Ben Greear48014162011-01-15 19:13:48 +00001159 mutex_unlock(&sc->mutex);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301160 return 0;
Ben Greear48014162011-01-15 19:13:48 +00001161}
1162
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301163static int ath9k_change_interface(struct ieee80211_hw *hw,
1164 struct ieee80211_vif *vif,
1165 enum nl80211_iftype new_type,
1166 bool p2p)
1167{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001168 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301169 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc083ce92014-06-11 16:17:54 +05301170 struct ath_vif *avp = (void *)vif->drv_priv;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301171 int i;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301172
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301173 mutex_lock(&sc->mutex);
Ben Greear48014162011-01-15 19:13:48 +00001174
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001175 if (config_enabled(CONFIG_ATH9K_TX99)) {
1176 mutex_unlock(&sc->mutex);
1177 return -EOPNOTSUPP;
1178 }
1179
1180 ath_dbg(common, CONFIG, "Change Interface\n");
1181
Ben Greear48014162011-01-15 19:13:48 +00001182 if (ath9k_uses_beacons(vif->type))
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301183 ath9k_beacon_remove_slot(sc, vif);
Ben Greear48014162011-01-15 19:13:48 +00001184
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301185 vif->type = new_type;
1186 vif->p2p = p2p;
1187
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301188 if (ath9k_uses_beacons(vif->type))
1189 ath9k_beacon_assign_slot(sc, vif);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301190
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301191 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1192 vif->hw_queue[i] = i;
1193
1194 if (vif->type == NL80211_IFTYPE_AP)
1195 vif->cab_queue = hw->queues - 2;
1196 else
1197 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
1198
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301199 ath9k_calculate_summary_state(sc, avp->chanctx);
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301200
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301201 mutex_unlock(&sc->mutex);
Mohammed Shafi Shajakhan327967c2012-09-04 19:33:36 +05301202 return 0;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301203}
1204
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001205static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001206 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001207{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001208 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001209 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001210 struct ath_vif *avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001211
Joe Perchesd2182b62011-12-15 14:55:53 -08001212 ath_dbg(common, CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001213
Sujith141b38b2009-02-04 08:10:07 +05301214 mutex_lock(&sc->mutex);
1215
Felix Fietkaud463af42014-04-06 00:37:03 +02001216 spin_lock_bh(&sc->sc_pcu_lock);
1217 if (avp == sc->p2p_ps_vif) {
1218 sc->p2p_ps_vif = NULL;
1219 ath9k_update_p2p_ps_timer(sc, NULL);
1220 }
1221 spin_unlock_bh(&sc->sc_pcu_lock);
1222
Ben Greear48014162011-01-15 19:13:48 +00001223 sc->nvifs--;
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001224 sc->tx99_vif = NULL;
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301225 if (!ath9k_use_chanctx)
1226 list_del(&avp->list);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001227
Ben Greear48014162011-01-15 19:13:48 +00001228 if (ath9k_uses_beacons(vif->type))
Sujith Manoharan130ef6e2012-07-17 17:15:30 +05301229 ath9k_beacon_remove_slot(sc, vif);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001230
Felix Fietkauf89d1bc2013-08-06 14:18:13 +02001231 ath_tx_node_cleanup(sc, &avp->mcast_node);
1232
Sujith141b38b2009-02-04 08:10:07 +05301233 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001234}
1235
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301236static void ath9k_enable_ps(struct ath_softc *sc)
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301237{
Pavel Roskin30691682010-03-31 18:05:31 -04001238 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301239 struct ath_common *common = ath9k_hw_common(ah);
Pavel Roskin30691682010-03-31 18:05:31 -04001240
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001241 if (config_enabled(CONFIG_ATH9K_TX99))
1242 return;
1243
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301244 sc->ps_enabled = true;
Pavel Roskin30691682010-03-31 18:05:31 -04001245 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1246 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1247 ah->imask |= ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001248 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301249 }
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001250 ath9k_hw_setrxabort(ah, 1);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301251 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301252 ath_dbg(common, PS, "PowerSave enabled\n");
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301253}
1254
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301255static void ath9k_disable_ps(struct ath_softc *sc)
1256{
1257 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301258 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301259
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001260 if (config_enabled(CONFIG_ATH9K_TX99))
1261 return;
1262
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301263 sc->ps_enabled = false;
1264 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1265 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1266 ath9k_hw_setrxabort(ah, 0);
1267 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1268 PS_WAIT_FOR_CAB |
1269 PS_WAIT_FOR_PSPOLL_DATA |
1270 PS_WAIT_FOR_TX_ACK);
1271 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1272 ah->imask &= ~ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001273 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301274 }
1275 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301276 ath_dbg(common, PS, "PowerSave disabled\n");
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301277}
1278
Simon Wunderliche93d0832013-01-08 14:48:58 +01001279void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
1280{
1281 struct ath_softc *sc = hw->priv;
1282 struct ath_hw *ah = sc->sc_ah;
1283 struct ath_common *common = ath9k_hw_common(ah);
1284 u32 rxfilter;
1285
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001286 if (config_enabled(CONFIG_ATH9K_TX99))
1287 return;
1288
Simon Wunderliche93d0832013-01-08 14:48:58 +01001289 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1290 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1291 return;
1292 }
1293
1294 ath9k_ps_wakeup(sc);
1295 rxfilter = ath9k_hw_getrxfilter(ah);
1296 ath9k_hw_setrxfilter(ah, rxfilter |
1297 ATH9K_RX_FILTER_PHYRADAR |
1298 ATH9K_RX_FILTER_PHYERR);
1299
1300 /* TODO: usually this should not be neccesary, but for some reason
1301 * (or in some mode?) the trigger must be called after the
1302 * configuration, otherwise the register will have its values reset
1303 * (on my ar9220 to value 0x01002310)
1304 */
1305 ath9k_spectral_scan_config(hw, sc->spectral_mode);
1306 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
1307 ath9k_ps_restore(sc);
1308}
1309
1310int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
1311 enum spectral_mode spectral_mode)
1312{
1313 struct ath_softc *sc = hw->priv;
1314 struct ath_hw *ah = sc->sc_ah;
1315 struct ath_common *common = ath9k_hw_common(ah);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001316
1317 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1318 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1319 return -1;
1320 }
1321
Simon Wunderliche93d0832013-01-08 14:48:58 +01001322 switch (spectral_mode) {
1323 case SPECTRAL_DISABLED:
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001324 sc->spec_config.enabled = 0;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001325 break;
1326 case SPECTRAL_BACKGROUND:
1327 /* send endless samples.
1328 * TODO: is this really useful for "background"?
1329 */
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001330 sc->spec_config.endless = 1;
1331 sc->spec_config.enabled = 1;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001332 break;
1333 case SPECTRAL_CHANSCAN:
Simon Wunderliche93d0832013-01-08 14:48:58 +01001334 case SPECTRAL_MANUAL:
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001335 sc->spec_config.endless = 0;
1336 sc->spec_config.enabled = 1;
Simon Wunderliche93d0832013-01-08 14:48:58 +01001337 break;
1338 default:
1339 return -1;
1340 }
1341
1342 ath9k_ps_wakeup(sc);
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +01001343 ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
Simon Wunderliche93d0832013-01-08 14:48:58 +01001344 ath9k_ps_restore(sc);
1345
1346 sc->spectral_mode = spectral_mode;
1347
1348 return 0;
1349}
1350
Johannes Berge8975582008-10-09 12:18:51 +02001351static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001353 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001354 struct ath_hw *ah = sc->sc_ah;
1355 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berge8975582008-10-09 12:18:51 +02001356 struct ieee80211_conf *conf = &hw->conf;
Felix Fietkaufbbcd142014-06-11 16:17:49 +05301357 struct ath_chanctx *ctx = sc->cur_chan;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001358
Felix Fietkauc0c11742011-11-16 13:08:41 +01001359 ath9k_ps_wakeup(sc);
Sujithaa33de02008-12-18 11:40:16 +05301360 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301361
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001362 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Felix Fietkau7545daf2011-01-24 19:23:16 +01001363 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301364 if (sc->ps_idle) {
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001365 ath_cancel_work(sc);
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301366 ath9k_stop_btcoex(sc);
1367 } else {
1368 ath9k_start_btcoex(sc);
Felix Fietkau75600ab2012-04-12 20:36:31 +02001369 /*
1370 * The chip needs a reset to properly wake up from
1371 * full sleep
1372 */
Felix Fietkau39305632014-06-11 16:17:57 +05301373 ath_chanctx_set_channel(sc, ctx, &ctx->chandef);
Rajkumar Manoharanb73f3e72012-07-01 19:53:53 +05301374 }
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001375 }
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001376
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001377 /*
1378 * We just prepare to enable PS. We have to wait until our AP has
1379 * ACK'd our null data frame to disable RX otherwise we'll ignore
1380 * those ACKs and end up retransmitting the same null data frames.
1381 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1382 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301383 if (changed & IEEE80211_CONF_CHANGE_PS) {
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001384 unsigned long flags;
1385 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301386 if (conf->flags & IEEE80211_CONF_PS)
1387 ath9k_enable_ps(sc);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301388 else
1389 ath9k_disable_ps(sc);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001390 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301391 }
1392
Sujith199afd92010-01-08 10:36:13 +05301393 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1394 if (conf->flags & IEEE80211_CONF_MONITOR) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001395 ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301396 sc->sc_ah->is_monitoring = true;
1397 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -08001398 ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301399 sc->sc_ah->is_monitoring = false;
Sujith199afd92010-01-08 10:36:13 +05301400 }
1401 }
1402
Felix Fietkau39305632014-06-11 16:17:57 +05301403 if (!ath9k_use_chanctx && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
Felix Fietkaufbbcd142014-06-11 16:17:49 +05301404 ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
Felix Fietkaubff11762014-06-11 16:17:52 +05301405 ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef);
Sujith094d05d2008-12-12 11:57:43 +05301406 }
Sujith86b89ee2008-08-07 10:54:57 +05301407
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001408 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001409 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +05301410 sc->cur_chan->txpower = 2 * conf->power_level;
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +05301411 ath9k_cmn_update_txpow(ah, sc->curtxpow,
Felix Fietkaubc7e1be2014-06-11 16:17:50 +05301412 sc->cur_chan->txpower, &sc->curtxpow);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001413 }
1414
Sujithaa33de02008-12-18 11:40:16 +05301415 mutex_unlock(&sc->mutex);
Felix Fietkauc0c11742011-11-16 13:08:41 +01001416 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001418 return 0;
1419}
1420
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001421#define SUPPORTED_FILTERS \
1422 (FIF_PROMISC_IN_BSS | \
1423 FIF_ALLMULTI | \
1424 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001425 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001426 FIF_OTHER_BSS | \
1427 FIF_BCN_PRBRESP_PROMISC | \
Jouni Malinen9c1d8e42010-10-13 17:29:31 +03001428 FIF_PROBE_REQ | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001429 FIF_FCSFAIL)
1430
Sujith7dcfdcd2008-08-11 14:03:13 +05301431/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001432static void ath9k_configure_filter(struct ieee80211_hw *hw,
1433 unsigned int changed_flags,
1434 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001435 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001436{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001437 struct ath_softc *sc = hw->priv;
Sujith7dcfdcd2008-08-11 14:03:13 +05301438 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001439
1440 changed_flags &= SUPPORTED_FILTERS;
1441 *total_flags &= SUPPORTED_FILTERS;
1442
Sujithb77f4832008-12-07 21:44:03 +05301443 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001444 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301445 rfilt = ath_calcrxfilter(sc);
1446 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001447 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301448
Joe Perchesd2182b62011-12-15 14:55:53 -08001449 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
1450 rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001451}
1452
Johannes Berg4ca77862010-02-19 19:06:56 +01001453static int ath9k_sta_add(struct ieee80211_hw *hw,
1454 struct ieee80211_vif *vif,
1455 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001456{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001457 struct ath_softc *sc = hw->priv;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001458 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1459 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1460 struct ieee80211_key_conf ps_key = { };
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001461 int key;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462
Ben Greear7e1e3862011-11-03 11:33:13 -07001463 ath_node_attach(sc, sta, vif);
Felix Fietkauf59a59f2011-05-10 20:52:22 +02001464
1465 if (vif->type != NL80211_IFTYPE_AP &&
1466 vif->type != NL80211_IFTYPE_AP_VLAN)
1467 return 0;
1468
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001469 key = ath_key_config(common, vif, sta, &ps_key);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301470 if (key > 0) {
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001471 an->ps_key = key;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301472 an->key_idx[0] = key;
1473 }
Johannes Berg4ca77862010-02-19 19:06:56 +01001474
1475 return 0;
1476}
1477
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001478static void ath9k_del_ps_key(struct ath_softc *sc,
1479 struct ieee80211_vif *vif,
1480 struct ieee80211_sta *sta)
1481{
1482 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1483 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1484 struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
1485
1486 if (!an->ps_key)
1487 return;
1488
1489 ath_key_delete(common, &ps_key);
Felix Fietkau4ef69d02013-04-27 11:47:01 +02001490 an->ps_key = 0;
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301491 an->key_idx[0] = 0;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001492}
1493
Johannes Berg4ca77862010-02-19 19:06:56 +01001494static int ath9k_sta_remove(struct ieee80211_hw *hw,
1495 struct ieee80211_vif *vif,
1496 struct ieee80211_sta *sta)
1497{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001498 struct ath_softc *sc = hw->priv;
Johannes Berg4ca77862010-02-19 19:06:56 +01001499
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001500 ath9k_del_ps_key(sc, vif, sta);
Johannes Berg4ca77862010-02-19 19:06:56 +01001501 ath_node_detach(sc, sta);
1502
1503 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001504}
1505
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301506static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
1507 struct ath_node *an,
1508 bool set)
1509{
1510 int i;
1511
1512 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1513 if (!an->key_idx[i])
1514 continue;
1515 ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
1516 }
1517}
1518
Felix Fietkau55195412011-04-17 23:28:09 +02001519static void ath9k_sta_notify(struct ieee80211_hw *hw,
1520 struct ieee80211_vif *vif,
1521 enum sta_notify_cmd cmd,
1522 struct ieee80211_sta *sta)
1523{
1524 struct ath_softc *sc = hw->priv;
1525 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1526
1527 switch (cmd) {
1528 case STA_NOTIFY_SLEEP:
1529 an->sleeping = true;
Johannes Berg042ec452011-09-29 16:04:26 +02001530 ath_tx_aggr_sleep(sta, sc, an);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301531 ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
Felix Fietkau55195412011-04-17 23:28:09 +02001532 break;
1533 case STA_NOTIFY_AWAKE:
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301534 ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
Felix Fietkau55195412011-04-17 23:28:09 +02001535 an->sleeping = false;
1536 ath_tx_aggr_wakeup(sc, an);
1537 break;
1538 }
1539}
1540
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001541static int ath9k_conf_tx(struct ieee80211_hw *hw,
1542 struct ieee80211_vif *vif, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001543 const struct ieee80211_tx_queue_params *params)
1544{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001545 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001546 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau066dae92010-11-07 14:59:39 +01001547 struct ath_txq *txq;
Sujithea9880f2008-08-07 10:53:10 +05301548 struct ath9k_tx_queue_info qi;
Felix Fietkau066dae92010-11-07 14:59:39 +01001549 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001550
Sujith Manoharanbea843c2012-11-21 18:13:10 +05301551 if (queue >= IEEE80211_NUM_ACS)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001552 return 0;
1553
Felix Fietkau066dae92010-11-07 14:59:39 +01001554 txq = sc->tx.txq_map[queue];
1555
Felix Fietkau96f372c2011-04-07 19:07:17 +02001556 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301557 mutex_lock(&sc->mutex);
1558
Sujith1ffb0612009-03-30 15:28:46 +05301559 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1560
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001561 qi.tqi_aifs = params->aifs;
1562 qi.tqi_cwmin = params->cw_min;
1563 qi.tqi_cwmax = params->cw_max;
Felix Fietkau531bd072012-07-15 19:53:34 +02001564 qi.tqi_burstTime = params->txop * 32;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565
Joe Perchesd2182b62011-12-15 14:55:53 -08001566 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -08001567 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1568 queue, txq->axq_qnum, params->aifs, params->cw_min,
1569 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001570
Felix Fietkauaa5955c2012-07-15 19:53:36 +02001571 ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
Felix Fietkau066dae92010-11-07 14:59:39 +01001572 ret = ath_txq_update(sc, txq->axq_qnum, &qi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001573 if (ret)
Joe Perches38002762010-12-02 19:12:36 -08001574 ath_err(common, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001575
Sujith141b38b2009-02-04 08:10:07 +05301576 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001577 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301578
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001579 return ret;
1580}
1581
1582static int ath9k_set_key(struct ieee80211_hw *hw,
1583 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001584 struct ieee80211_vif *vif,
1585 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586 struct ieee80211_key_conf *key)
1587{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001588 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001589 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301590 struct ath_node *an = NULL;
1591 int ret = 0, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001592
John W. Linville3e6109c2011-01-05 09:39:17 -05001593 if (ath9k_modparam_nohwcrypt)
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001594 return -ENOSPC;
1595
Chun-Yeow Yeoh5bd5e9a2011-12-07 12:45:46 -08001596 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1597 vif->type == NL80211_IFTYPE_MESH_POINT) &&
Jouni Malinencfdc9a82011-03-23 14:52:19 +02001598 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1599 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1600 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1601 /*
1602 * For now, disable hw crypto for the RSN IBSS group keys. This
1603 * could be optimized in the future to use a modified key cache
1604 * design to support per-STA RX GTK, but until that gets
1605 * implemented, use of software crypto for group addressed
1606 * frames is a acceptable to allow RSN IBSS to be used.
1607 */
1608 return -EOPNOTSUPP;
1609 }
1610
Sujith141b38b2009-02-04 08:10:07 +05301611 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301612 ath9k_ps_wakeup(sc);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301613 ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
1614 if (sta)
1615 an = (struct ath_node *)sta->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001616
1617 switch (cmd) {
1618 case SET_KEY:
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001619 if (sta)
1620 ath9k_del_ps_key(sc, vif, sta);
1621
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301622 key->hw_key_idx = 0;
Bruno Randolf040e5392010-09-08 16:05:04 +09001623 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001624 if (ret >= 0) {
1625 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001626 /* push IV and Michael MIC generation to stack */
1627 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Johannes Berg97359d12010-08-10 09:46:38 +02001628 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301629 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg97359d12010-08-10 09:46:38 +02001630 if (sc->sc_ah->sw_mgmt_crypto &&
1631 key->cipher == WLAN_CIPHER_SUITE_CCMP)
Johannes Berge548c492012-09-04 17:08:23 +02001632 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001633 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001634 }
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301635 if (an && key->hw_key_idx) {
1636 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1637 if (an->key_idx[i])
1638 continue;
1639 an->key_idx[i] = key->hw_key_idx;
1640 break;
1641 }
1642 WARN_ON(i == ARRAY_SIZE(an->key_idx));
1643 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001644 break;
1645 case DISABLE_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001646 ath_key_delete(common, key);
Rajkumar Manoharan4bbf4412014-05-22 12:35:49 +05301647 if (an) {
1648 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1649 if (an->key_idx[i] != key->hw_key_idx)
1650 continue;
1651 an->key_idx[i] = 0;
1652 break;
1653 }
1654 }
1655 key->hw_key_idx = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001656 break;
1657 default:
1658 ret = -EINVAL;
1659 }
1660
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301661 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301662 mutex_unlock(&sc->mutex);
1663
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001664 return ret;
1665}
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301666
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001667static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1668 struct ieee80211_vif *vif,
1669 struct ieee80211_bss_conf *bss_conf,
1670 u32 changed)
1671{
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301672#define CHECK_ANI \
1673 (BSS_CHANGED_ASSOC | \
1674 BSS_CHANGED_IBSS | \
1675 BSS_CHANGED_BEACON_ENABLED)
1676
Felix Fietkau9ac586152011-01-24 19:23:18 +01001677 struct ath_softc *sc = hw->priv;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001678 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001679 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001680 struct ath_vif *avp = (void *)vif->drv_priv;
Rajkumar Manoharan60ccc102014-05-27 16:58:02 +05301681 unsigned long flags;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001682 int slottime;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001683
Felix Fietkau96f372c2011-04-07 19:07:17 +02001684 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301685 mutex_lock(&sc->mutex);
1686
Rajkumar Manoharan9f619032012-03-10 05:06:49 +05301687 if (changed & BSS_CHANGED_ASSOC) {
Sujith Manoharan6c43c0902012-07-17 17:15:50 +05301688 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
1689 bss_conf->bssid, bss_conf->assoc);
Sujithc6089cc2009-11-16 11:40:48 +05301690
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301691 ath9k_calculate_summary_state(sc, avp->chanctx);
Felix Fietkau73fa2f22014-06-11 16:18:10 +05301692 if (bss_conf->assoc)
1693 ath_chanctx_event(sc, vif, ATH_CHANCTX_EVENT_ASSOC);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001694 }
1695
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301696 if (changed & BSS_CHANGED_IBSS) {
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301697 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1698 common->curaid = bss_conf->aid;
1699 ath9k_hw_write_associd(sc->sc_ah);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301700 }
1701
Sujith Manoharanef4ad632012-07-17 17:15:56 +05301702 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
Rajkumar Manoharan9198cf42014-06-26 16:54:40 +05301703 (changed & BSS_CHANGED_BEACON_INT) ||
1704 (changed & BSS_CHANGED_BEACON_INFO)) {
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301705 if (changed & BSS_CHANGED_BEACON_ENABLED)
1706 ath9k_calculate_summary_state(sc, avp->chanctx);
Felix Fietkauc32e4e52013-12-19 18:01:49 +01001707 ath9k_beacon_config(sc, vif, changed);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301708 }
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001709
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05301710 if ((avp->chanctx == sc->cur_chan) &&
1711 (changed & BSS_CHANGED_ERP_SLOT)) {
Felix Fietkau0005baf2010-01-15 02:33:40 +01001712 if (bss_conf->use_short_slot)
1713 slottime = 9;
1714 else
1715 slottime = 20;
1716 if (vif->type == NL80211_IFTYPE_AP) {
1717 /*
1718 * Defer update, so that connected stations can adjust
1719 * their settings at the same time.
1720 * See beacon.c for more details
1721 */
1722 sc->beacon.slottime = slottime;
1723 sc->beacon.updateslot = UPDATE;
1724 } else {
1725 ah->slottime = slottime;
1726 ath9k_hw_init_global_settings(ah);
1727 }
1728 }
1729
Felix Fietkaud463af42014-04-06 00:37:03 +02001730 if (changed & BSS_CHANGED_P2P_PS) {
1731 spin_lock_bh(&sc->sc_pcu_lock);
Rajkumar Manoharan60ccc102014-05-27 16:58:02 +05301732 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1733 if (!(sc->ps_flags & PS_BEACON_SYNC))
1734 ath9k_update_p2p_ps(sc, vif);
1735 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Felix Fietkaud463af42014-04-06 00:37:03 +02001736 spin_unlock_bh(&sc->sc_pcu_lock);
1737 }
1738
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301739 if (changed & CHECK_ANI)
1740 ath_check_ani(sc);
1741
Sujith141b38b2009-02-04 08:10:07 +05301742 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001743 ath9k_ps_restore(sc);
Sujith Manoharanda0d45f2012-07-17 17:16:29 +05301744
1745#undef CHECK_ANI
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001746}
1747
Eliad Peller37a41b42011-09-21 14:06:11 +03001748static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001749{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001750 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001751 u64 tsf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001752
Sujith141b38b2009-02-04 08:10:07 +05301753 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301754 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301755 tsf = ath9k_hw_gettsf64(sc->sc_ah);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301756 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301757 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001758
1759 return tsf;
1760}
1761
Eliad Peller37a41b42011-09-21 14:06:11 +03001762static void ath9k_set_tsf(struct ieee80211_hw *hw,
1763 struct ieee80211_vif *vif,
1764 u64 tsf)
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001765{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001766 struct ath_softc *sc = hw->priv;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001767
Sujith141b38b2009-02-04 08:10:07 +05301768 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301769 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301770 ath9k_hw_settsf64(sc->sc_ah, tsf);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301771 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301772 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001773}
1774
Eliad Peller37a41b42011-09-21 14:06:11 +03001775static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001777 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001778
Sujith141b38b2009-02-04 08:10:07 +05301779 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001780
1781 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301782 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001783 ath9k_ps_restore(sc);
1784
Sujith141b38b2009-02-04 08:10:07 +05301785 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786}
1787
1788static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01001789 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05301790 enum ieee80211_ampdu_mlme_action action,
1791 struct ieee80211_sta *sta,
Johannes Berg0b01f032011-01-18 13:51:05 +01001792 u16 tid, u16 *ssn, u8 buf_size)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001793{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001794 struct ath_softc *sc = hw->priv;
Felix Fietkau16e23422013-05-17 12:58:24 +02001795 bool flush = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796 int ret = 0;
1797
Sujith Manoharan7ca7c772013-05-08 05:03:32 +05301798 mutex_lock(&sc->mutex);
Johannes Berg85ad1812010-06-10 10:21:49 +02001799
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001800 switch (action) {
1801 case IEEE80211_AMPDU_RX_START:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802 break;
1803 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001804 break;
1805 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001806 ath9k_ps_wakeup(sc);
Felix Fietkau231c3a12010-09-20 19:35:28 +02001807 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1808 if (!ret)
1809 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001810 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001811 break;
Johannes Berg18b559d2012-07-18 13:51:25 +02001812 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1813 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
Felix Fietkau16e23422013-05-17 12:58:24 +02001814 flush = true;
1815 case IEEE80211_AMPDU_TX_STOP_CONT:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001816 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301817 ath_tx_aggr_stop(sc, sta, tid);
Felix Fietkau08c96ab2013-05-18 21:28:15 +02001818 if (!flush)
Felix Fietkau16e23422013-05-17 12:58:24 +02001819 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001820 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001821 break;
Johannes Bergb1720232009-03-23 17:28:39 +01001822 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001823 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05301824 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001825 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05301826 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001827 default:
Joe Perches38002762010-12-02 19:12:36 -08001828 ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829 }
1830
Sujith Manoharan7ca7c772013-05-08 05:03:32 +05301831 mutex_unlock(&sc->mutex);
Johannes Berg85ad1812010-06-10 10:21:49 +02001832
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001833 return ret;
1834}
1835
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001836static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
1837 struct survey_info *survey)
1838{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001839 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001840 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39162db2010-09-29 19:12:06 +02001841 struct ieee80211_supported_band *sband;
Felix Fietkau34300982010-10-10 18:21:52 +02001842 struct ieee80211_channel *chan;
Felix Fietkau34300982010-10-10 18:21:52 +02001843 int pos;
1844
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001845 if (config_enabled(CONFIG_ATH9K_TX99))
1846 return -EOPNOTSUPP;
1847
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301848 spin_lock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001849 if (idx == 0)
1850 ath_update_survey_stats(sc);
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001851
Felix Fietkau39162db2010-09-29 19:12:06 +02001852 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
1853 if (sband && idx >= sband->n_channels) {
1854 idx -= sband->n_channels;
1855 sband = NULL;
1856 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001857
Felix Fietkau39162db2010-09-29 19:12:06 +02001858 if (!sband)
1859 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
1860
Felix Fietkau34300982010-10-10 18:21:52 +02001861 if (!sband || idx >= sband->n_channels) {
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301862 spin_unlock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001863 return -ENOENT;
Felix Fietkau4f1a5a42010-09-29 17:15:28 +02001864 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001865
Felix Fietkau34300982010-10-10 18:21:52 +02001866 chan = &sband->channels[idx];
1867 pos = chan->hw_value;
1868 memcpy(survey, &sc->survey[pos], sizeof(*survey));
1869 survey->channel = chan;
Sujith Manoharanb7cc9b92013-12-26 08:14:40 +05301870 spin_unlock_bh(&common->cc_lock);
Felix Fietkau34300982010-10-10 18:21:52 +02001871
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001872 return 0;
1873}
1874
Felix Fietkaue239d852010-01-15 02:34:58 +01001875static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
1876{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001877 struct ath_softc *sc = hw->priv;
Felix Fietkaue239d852010-01-15 02:34:58 +01001878 struct ath_hw *ah = sc->sc_ah;
1879
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -07001880 if (config_enabled(CONFIG_ATH9K_TX99))
1881 return;
1882
Felix Fietkaue239d852010-01-15 02:34:58 +01001883 mutex_lock(&sc->mutex);
1884 ah->coverage_class = coverage_class;
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301885
1886 ath9k_ps_wakeup(sc);
Felix Fietkaue239d852010-01-15 02:34:58 +01001887 ath9k_hw_init_global_settings(ah);
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301888 ath9k_ps_restore(sc);
1889
Felix Fietkaue239d852010-01-15 02:34:58 +01001890 mutex_unlock(&sc->mutex);
1891}
1892
Felix Fietkau10e23182013-11-11 22:23:35 +01001893static bool ath9k_has_tx_pending(struct ath_softc *sc)
1894{
Geert Uytterhoevenf7838072014-01-26 11:53:21 +01001895 int i, npend = 0;
Felix Fietkau10e23182013-11-11 22:23:35 +01001896
1897 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1898 if (!ATH_TXQ_SETUP(sc, i))
1899 continue;
1900
1901 if (!sc->tx.txq[i].axq_depth)
1902 continue;
1903
1904 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
1905 if (npend)
1906 break;
1907 }
1908
1909 return !!npend;
1910}
1911
Emmanuel Grumbach77be2c52014-03-27 11:30:29 +02001912static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1913 u32 queues, bool drop)
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001914{
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001915 struct ath_softc *sc = hw->priv;
Felix Fietkaubff11762014-06-11 16:17:52 +05301916
1917 mutex_lock(&sc->mutex);
1918 __ath9k_flush(hw, queues, drop);
1919 mutex_unlock(&sc->mutex);
1920}
1921
1922void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1923{
1924 struct ath_softc *sc = hw->priv;
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301925 struct ath_hw *ah = sc->sc_ah;
1926 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau10e23182013-11-11 22:23:35 +01001927 int timeout = HZ / 5; /* 200 ms */
Rajkumar Manoharan2f6fc352011-04-28 15:31:57 +05301928 bool drain_txq;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301929 int i;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001930
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001931 cancel_delayed_work_sync(&sc->tx_complete_work);
1932
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301933 if (ah->ah_flags & AH_UNPLUGGED) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001934 ath_dbg(common, ANY, "Device has been unplugged!\n");
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301935 return;
1936 }
1937
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01001938 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001939 ath_dbg(common, ANY, "Device not present\n");
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301940 return;
1941 }
1942
Felix Fietkau10e23182013-11-11 22:23:35 +01001943 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
1944 timeout) > 0)
1945 drop = false;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001946
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001947 if (drop) {
1948 ath9k_ps_wakeup(sc);
1949 spin_lock_bh(&sc->sc_pcu_lock);
Felix Fietkau13815592013-01-20 18:51:53 +01001950 drain_txq = ath_drain_all_txq(sc);
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001951 spin_unlock_bh(&sc->sc_pcu_lock);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001952
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001953 if (!drain_txq)
Felix Fietkau13815592013-01-20 18:51:53 +01001954 ath_reset(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001955
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001956 ath9k_ps_restore(sc);
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05301957 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
1958 ieee80211_wake_queue(sc->hw,
1959 sc->cur_chan->hw_queue_base + i);
1960 }
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001961 }
Senthil Balasubramaniand78f4b32011-03-23 23:07:22 +05301962
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001963 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001964}
1965
Vivek Natarajan15b91e82011-04-06 11:41:11 +05301966static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
1967{
1968 struct ath_softc *sc = hw->priv;
1969 int i;
1970
1971 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1972 if (!ATH_TXQ_SETUP(sc, i))
1973 continue;
1974
1975 if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
1976 return true;
1977 }
1978 return false;
1979}
1980
Mohammed Shafi Shajakhan5595f112011-05-19 18:08:57 +05301981static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
Felix Fietkauba4903f2011-05-17 21:09:54 +02001982{
1983 struct ath_softc *sc = hw->priv;
1984 struct ath_hw *ah = sc->sc_ah;
1985 struct ieee80211_vif *vif;
1986 struct ath_vif *avp;
1987 struct ath_buf *bf;
1988 struct ath_tx_status ts;
Felix Fietkau4286df62012-02-27 19:58:40 +01001989 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Felix Fietkauba4903f2011-05-17 21:09:54 +02001990 int status;
1991
1992 vif = sc->beacon.bslot[0];
1993 if (!vif)
1994 return 0;
1995
Sujith Manoharanaa45fe92012-07-17 17:16:03 +05301996 if (!vif->bss_conf.enable_beacon)
Felix Fietkauba4903f2011-05-17 21:09:54 +02001997 return 0;
1998
Sujith Manoharanaa45fe92012-07-17 17:16:03 +05301999 avp = (void *)vif->drv_priv;
2000
Felix Fietkau4286df62012-02-27 19:58:40 +01002001 if (!sc->beacon.tx_processed && !edma) {
Felix Fietkauba4903f2011-05-17 21:09:54 +02002002 tasklet_disable(&sc->bcon_tasklet);
2003
2004 bf = avp->av_bcbuf;
2005 if (!bf || !bf->bf_mpdu)
2006 goto skip;
2007
2008 status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
2009 if (status == -EINPROGRESS)
2010 goto skip;
2011
2012 sc->beacon.tx_processed = true;
2013 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
2014
2015skip:
2016 tasklet_enable(&sc->bcon_tasklet);
2017 }
2018
2019 return sc->beacon.tx_last;
2020}
2021
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302022static int ath9k_get_stats(struct ieee80211_hw *hw,
2023 struct ieee80211_low_level_stats *stats)
2024{
2025 struct ath_softc *sc = hw->priv;
2026 struct ath_hw *ah = sc->sc_ah;
2027 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
2028
2029 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
2030 stats->dot11RTSFailureCount = mib_stats->rts_bad;
2031 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
2032 stats->dot11RTSSuccessCount = mib_stats->rts_good;
2033 return 0;
2034}
2035
Felix Fietkau43c35282011-09-03 01:40:27 +02002036static u32 fill_chainmask(u32 cap, u32 new)
2037{
2038 u32 filled = 0;
2039 int i;
2040
2041 for (i = 0; cap && new; i++, cap >>= 1) {
2042 if (!(cap & BIT(0)))
2043 continue;
2044
2045 if (new & BIT(0))
2046 filled |= BIT(i);
2047
2048 new >>= 1;
2049 }
2050
2051 return filled;
2052}
2053
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002054static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
2055{
Felix Fietkaufea92cb2013-01-20 21:55:22 +01002056 if (AR_SREV_9300_20_OR_LATER(ah))
2057 return true;
2058
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002059 switch (val & 0x7) {
2060 case 0x1:
2061 case 0x3:
2062 case 0x7:
2063 return true;
2064 case 0x2:
2065 return (ah->caps.rx_chainmask == 1);
2066 default:
2067 return false;
2068 }
2069}
2070
Felix Fietkau43c35282011-09-03 01:40:27 +02002071static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2072{
2073 struct ath_softc *sc = hw->priv;
2074 struct ath_hw *ah = sc->sc_ah;
2075
Felix Fietkau5d9c7e32012-07-15 19:53:30 +02002076 if (ah->caps.rx_chainmask != 1)
2077 rx_ant |= tx_ant;
2078
2079 if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
Felix Fietkau43c35282011-09-03 01:40:27 +02002080 return -EINVAL;
2081
2082 sc->ant_rx = rx_ant;
2083 sc->ant_tx = tx_ant;
2084
2085 if (ah->caps.rx_chainmask == 1)
2086 return 0;
2087
2088 /* AR9100 runs into calibration issues if not all rx chains are enabled */
2089 if (AR_SREV_9100(ah))
2090 ah->rxchainmask = 0x7;
2091 else
2092 ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
2093
2094 ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
Oleksij Rempelb57ba3b2014-02-25 14:48:55 +01002095 ath9k_cmn_reload_chainmask(ah);
Felix Fietkau43c35282011-09-03 01:40:27 +02002096
2097 return 0;
2098}
2099
2100static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2101{
2102 struct ath_softc *sc = hw->priv;
2103
2104 *tx_ant = sc->ant_tx;
2105 *rx_ant = sc->ant_rx;
2106 return 0;
2107}
2108
Simon Wunderliche93d0832013-01-08 14:48:58 +01002109static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2110{
2111 struct ath_softc *sc = hw->priv;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002112 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2113 set_bit(ATH_OP_SCANNING, &common->op_flags);
Simon Wunderliche93d0832013-01-08 14:48:58 +01002114}
2115
2116static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2117{
2118 struct ath_softc *sc = hw->priv;
Oleksij Rempeleefa01d2014-02-27 11:40:46 +01002119 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2120 clear_bit(ATH_OP_SCANNING, &common->op_flags);
Simon Wunderliche93d0832013-01-08 14:48:58 +01002121}
Mohammed Shafi Shajakhanb11e6402012-07-10 14:56:52 +05302122
Felix Fietkau78b21942014-06-11 16:17:55 +05302123static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
John W. Linville855df362014-06-25 15:15:14 -04002124 struct ieee80211_scan_request *hw_req)
Felix Fietkau78b21942014-06-11 16:17:55 +05302125{
John W. Linville855df362014-06-25 15:15:14 -04002126 struct cfg80211_scan_request *req = &hw_req->req;
Felix Fietkau78b21942014-06-11 16:17:55 +05302127 struct ath_softc *sc = hw->priv;
2128 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2129 int ret = 0;
2130
2131 mutex_lock(&sc->mutex);
2132
2133 if (WARN_ON(sc->offchannel.scan_req)) {
2134 ret = -EBUSY;
2135 goto out;
2136 }
2137
2138 ath9k_ps_wakeup(sc);
2139 set_bit(ATH_OP_SCANNING, &common->op_flags);
2140 sc->offchannel.scan_vif = vif;
2141 sc->offchannel.scan_req = req;
2142 sc->offchannel.scan_idx = 0;
Felix Fietkau78b21942014-06-11 16:17:55 +05302143
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302144 ath_dbg(common, CHAN_CTX, "HW scan request received on vif: %pM\n",
2145 vif->addr);
2146
2147 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
2148 ath_dbg(common, CHAN_CTX, "Starting HW scan\n");
Felix Fietkau405393c2014-06-11 16:17:56 +05302149 ath_offchannel_next(sc);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302150 }
Felix Fietkau78b21942014-06-11 16:17:55 +05302151
2152out:
2153 mutex_unlock(&sc->mutex);
2154
2155 return ret;
2156}
2157
2158static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw,
2159 struct ieee80211_vif *vif)
2160{
2161 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302162 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2163
2164 ath_dbg(common, CHAN_CTX, "Cancel HW scan on vif: %pM\n", vif->addr);
Felix Fietkau78b21942014-06-11 16:17:55 +05302165
2166 mutex_lock(&sc->mutex);
2167 del_timer_sync(&sc->offchannel.timer);
2168 ath_scan_complete(sc, true);
2169 mutex_unlock(&sc->mutex);
2170}
2171
Felix Fietkau405393c2014-06-11 16:17:56 +05302172static int ath9k_remain_on_channel(struct ieee80211_hw *hw,
2173 struct ieee80211_vif *vif,
2174 struct ieee80211_channel *chan, int duration,
2175 enum ieee80211_roc_type type)
2176{
2177 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302178 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau405393c2014-06-11 16:17:56 +05302179 int ret = 0;
2180
2181 mutex_lock(&sc->mutex);
2182
2183 if (WARN_ON(sc->offchannel.roc_vif)) {
2184 ret = -EBUSY;
2185 goto out;
2186 }
2187
2188 ath9k_ps_wakeup(sc);
2189 sc->offchannel.roc_vif = vif;
2190 sc->offchannel.roc_chan = chan;
2191 sc->offchannel.roc_duration = duration;
2192
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302193 ath_dbg(common, CHAN_CTX,
2194 "RoC request on vif: %pM, type: %d duration: %d\n",
2195 vif->addr, type, duration);
2196
2197 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
2198 ath_dbg(common, CHAN_CTX, "Starting RoC period\n");
Felix Fietkau405393c2014-06-11 16:17:56 +05302199 ath_offchannel_next(sc);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302200 }
Felix Fietkau405393c2014-06-11 16:17:56 +05302201
2202out:
2203 mutex_unlock(&sc->mutex);
2204
2205 return ret;
2206}
2207
2208static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2209{
2210 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302211 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau405393c2014-06-11 16:17:56 +05302212
2213 mutex_lock(&sc->mutex);
2214
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302215 ath_dbg(common, CHAN_CTX, "Cancel RoC\n");
Felix Fietkau405393c2014-06-11 16:17:56 +05302216 del_timer_sync(&sc->offchannel.timer);
2217
2218 if (sc->offchannel.roc_vif) {
2219 if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
2220 ath_roc_complete(sc, true);
2221 }
2222
2223 mutex_unlock(&sc->mutex);
2224
2225 return 0;
2226}
2227
Felix Fietkau39305632014-06-11 16:17:57 +05302228static int ath9k_add_chanctx(struct ieee80211_hw *hw,
2229 struct ieee80211_chanctx_conf *conf)
2230{
2231 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302232 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39305632014-06-11 16:17:57 +05302233 struct ath_chanctx *ctx, **ptr;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302234 int pos;
Felix Fietkau39305632014-06-11 16:17:57 +05302235
2236 mutex_lock(&sc->mutex);
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +05302237
2238 ath_for_each_chanctx(sc, ctx) {
2239 if (ctx->assigned)
2240 continue;
2241
2242 ptr = (void *) conf->drv_priv;
2243 *ptr = ctx;
2244 ctx->assigned = true;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302245 pos = ctx - &sc->chanctx[0];
2246 ctx->hw_queue_base = pos * IEEE80211_NUM_ACS;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302247
2248 ath_dbg(common, CHAN_CTX,
2249 "Add channel context: %d MHz\n",
2250 conf->def.chan->center_freq);
2251
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +05302252 ath_chanctx_set_channel(sc, ctx, &conf->def);
Felix Fietkau39305632014-06-11 16:17:57 +05302253 mutex_unlock(&sc->mutex);
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +05302254 return 0;
Felix Fietkau39305632014-06-11 16:17:57 +05302255 }
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302256
Felix Fietkau39305632014-06-11 16:17:57 +05302257 mutex_unlock(&sc->mutex);
Rajkumar Manoharanc4dc0d02014-06-11 16:17:58 +05302258 return -ENOSPC;
Felix Fietkau39305632014-06-11 16:17:57 +05302259}
2260
2261
2262static void ath9k_remove_chanctx(struct ieee80211_hw *hw,
2263 struct ieee80211_chanctx_conf *conf)
2264{
2265 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302266 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39305632014-06-11 16:17:57 +05302267 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2268
2269 mutex_lock(&sc->mutex);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302270
2271 ath_dbg(common, CHAN_CTX,
2272 "Remove channel context: %d MHz\n",
2273 conf->def.chan->center_freq);
2274
Felix Fietkau39305632014-06-11 16:17:57 +05302275 ctx->assigned = false;
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302276 ctx->hw_queue_base = -1;
Felix Fietkau73fa2f22014-06-11 16:18:10 +05302277 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302278
Felix Fietkau39305632014-06-11 16:17:57 +05302279 mutex_unlock(&sc->mutex);
2280}
2281
2282static void ath9k_change_chanctx(struct ieee80211_hw *hw,
2283 struct ieee80211_chanctx_conf *conf,
2284 u32 changed)
2285{
2286 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302287 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39305632014-06-11 16:17:57 +05302288 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2289
2290 mutex_lock(&sc->mutex);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302291 ath_dbg(common, CHAN_CTX,
2292 "Change channel context: %d MHz\n",
2293 conf->def.chan->center_freq);
Felix Fietkau39305632014-06-11 16:17:57 +05302294 ath_chanctx_set_channel(sc, ctx, &conf->def);
2295 mutex_unlock(&sc->mutex);
2296}
2297
2298static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
2299 struct ieee80211_vif *vif,
2300 struct ieee80211_chanctx_conf *conf)
2301{
2302 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302303 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39305632014-06-11 16:17:57 +05302304 struct ath_vif *avp = (void *)vif->drv_priv;
2305 struct ath_chanctx *ctx = ath_chanctx_get(conf);
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302306 int i;
Felix Fietkau39305632014-06-11 16:17:57 +05302307
2308 mutex_lock(&sc->mutex);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302309
2310 ath_dbg(common, CHAN_CTX,
2311 "Assign VIF (addr: %pM, type: %d, p2p: %d) to channel context: %d MHz\n",
2312 vif->addr, vif->type, vif->p2p,
2313 conf->def.chan->center_freq);
2314
Felix Fietkau39305632014-06-11 16:17:57 +05302315 avp->chanctx = ctx;
2316 list_add_tail(&avp->list, &ctx->vifs);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05302317 ath9k_calculate_summary_state(sc, ctx);
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302318 for (i = 0; i < IEEE80211_NUM_ACS; i++)
2319 vif->hw_queue[i] = ctx->hw_queue_base + i;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302320
Felix Fietkau39305632014-06-11 16:17:57 +05302321 mutex_unlock(&sc->mutex);
2322
2323 return 0;
2324}
2325
2326static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
2327 struct ieee80211_vif *vif,
2328 struct ieee80211_chanctx_conf *conf)
2329{
2330 struct ath_softc *sc = hw->priv;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302331 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39305632014-06-11 16:17:57 +05302332 struct ath_vif *avp = (void *)vif->drv_priv;
2333 struct ath_chanctx *ctx = ath_chanctx_get(conf);
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302334 int ac;
Felix Fietkau39305632014-06-11 16:17:57 +05302335
2336 mutex_lock(&sc->mutex);
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302337
2338 ath_dbg(common, CHAN_CTX,
2339 "Remove VIF (addr: %pM, type: %d, p2p: %d) from channel context: %d MHz\n",
2340 vif->addr, vif->type, vif->p2p,
2341 conf->def.chan->center_freq);
2342
Felix Fietkau39305632014-06-11 16:17:57 +05302343 avp->chanctx = NULL;
2344 list_del(&avp->list);
Rajkumar Manoharan9a9c4fb2014-06-11 16:18:03 +05302345 ath9k_calculate_summary_state(sc, ctx);
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +05302346 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2347 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302348
Felix Fietkau39305632014-06-11 16:17:57 +05302349 mutex_unlock(&sc->mutex);
2350}
2351
Felix Fietkau78b21942014-06-11 16:17:55 +05302352void ath9k_fill_chanctx_ops(void)
2353{
2354 if (!ath9k_use_chanctx)
2355 return;
2356
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302357 ath9k_ops.hw_scan = ath9k_hw_scan;
2358 ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
2359 ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
Felix Fietkau405393c2014-06-11 16:17:56 +05302360 ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
Sujith Manoharanbc81d432014-08-22 20:39:27 +05302361 ath9k_ops.add_chanctx = ath9k_add_chanctx;
2362 ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
2363 ath9k_ops.change_chanctx = ath9k_change_chanctx;
2364 ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
2365 ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
2366 ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
Felix Fietkau78b21942014-06-11 16:17:55 +05302367}
2368
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002369struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370 .tx = ath9k_tx,
2371 .start = ath9k_start,
2372 .stop = ath9k_stop,
2373 .add_interface = ath9k_add_interface,
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05302374 .change_interface = ath9k_change_interface,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002375 .remove_interface = ath9k_remove_interface,
2376 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002377 .configure_filter = ath9k_configure_filter,
Johannes Berg4ca77862010-02-19 19:06:56 +01002378 .sta_add = ath9k_sta_add,
2379 .sta_remove = ath9k_sta_remove,
Felix Fietkau55195412011-04-17 23:28:09 +02002380 .sta_notify = ath9k_sta_notify,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002381 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002382 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002383 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002385 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002386 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002387 .ampdu_action = ath9k_ampdu_action,
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002388 .get_survey = ath9k_get_survey,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302389 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002390 .set_coverage_class = ath9k_set_coverage_class,
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08002391 .flush = ath9k_flush,
Vivek Natarajan15b91e82011-04-06 11:41:11 +05302392 .tx_frames_pending = ath9k_tx_frames_pending,
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302393 .tx_last_beacon = ath9k_tx_last_beacon,
Felix Fietkau86a22ac2013-06-07 18:12:01 +02002394 .release_buffered_frames = ath9k_release_buffered_frames,
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302395 .get_stats = ath9k_get_stats,
Felix Fietkau43c35282011-09-03 01:40:27 +02002396 .set_antenna = ath9k_set_antenna,
2397 .get_antenna = ath9k_get_antenna,
Ben Greearb90bd9d2012-05-15 15:33:25 -07002398
Sujith Manoharane60001e2013-10-28 12:22:04 +05302399#ifdef CONFIG_ATH9K_WOW
Mohammed Shafi Shajakhanb11e6402012-07-10 14:56:52 +05302400 .suspend = ath9k_suspend,
2401 .resume = ath9k_resume,
2402 .set_wakeup = ath9k_set_wakeup,
2403#endif
2404
Ben Greearb90bd9d2012-05-15 15:33:25 -07002405#ifdef CONFIG_ATH9K_DEBUGFS
2406 .get_et_sset_count = ath9k_get_et_sset_count,
Sujith Manoharana145daf2012-11-28 15:08:54 +05302407 .get_et_stats = ath9k_get_et_stats,
2408 .get_et_strings = ath9k_get_et_strings,
2409#endif
2410
Sujith Manoharan1cdbaf02014-01-13 07:29:27 +05302411#if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
Sujith Manoharana145daf2012-11-28 15:08:54 +05302412 .sta_add_debugfs = ath9k_sta_add_debugfs,
Ben Greearb90bd9d2012-05-15 15:33:25 -07002413#endif
Simon Wunderliche93d0832013-01-08 14:48:58 +01002414 .sw_scan_start = ath9k_sw_scan_start,
2415 .sw_scan_complete = ath9k_sw_scan_complete,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002416};