blob: 88f7ad106e056796d7dd23c1d82241cb35ca3b55 [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
Sujithff37e332008-11-24 12:07:55 +053022static u8 parse_mpdudensity(u8 mpdudensity)
23{
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
63 if (txq->axq_depth || !list_empty(&txq->axq_acq))
64 pending = true;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -080065
66 spin_unlock_bh(&txq->axq_lock);
67 return pending;
68}
69
Mohammed Shafi Shajakhan6d79cb42011-05-19 17:40:46 +053070static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070071{
72 unsigned long flags;
73 bool ret;
74
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070075 spin_lock_irqsave(&sc->sc_pm_lock, flags);
76 ret = ath9k_hw_setpower(sc->sc_ah, mode);
77 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070078
79 return ret;
80}
81
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070082void ath9k_ps_wakeup(struct ath_softc *sc)
83{
Felix Fietkau898c9142010-10-12 14:02:53 +020084 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070085 unsigned long flags;
Felix Fietkaufbb078f2010-11-03 01:36:51 +010086 enum ath9k_power_mode power_mode;
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070087
88 spin_lock_irqsave(&sc->sc_pm_lock, flags);
89 if (++sc->ps_usecount != 1)
90 goto unlock;
91
Felix Fietkaufbb078f2010-11-03 01:36:51 +010092 power_mode = sc->sc_ah->power_mode;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070093 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070094
Felix Fietkau898c9142010-10-12 14:02:53 +020095 /*
96 * While the hardware is asleep, the cycle counters contain no
97 * useful data. Better clear them now so that they don't mess up
98 * survey data results.
99 */
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100100 if (power_mode != ATH9K_PM_AWAKE) {
101 spin_lock(&common->cc_lock);
102 ath_hw_cycle_counters_update(common);
103 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
Rajkumar Manoharanc9ae6ab2012-06-04 16:28:41 +0530104 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100105 spin_unlock(&common->cc_lock);
106 }
Felix Fietkau898c9142010-10-12 14:02:53 +0200107
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700108 unlock:
109 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
110}
111
112void ath9k_ps_restore(struct ath_softc *sc)
113{
Felix Fietkau898c9142010-10-12 14:02:53 +0200114 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200115 enum ath9k_power_mode mode;
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700116 unsigned long flags;
Sujith Manoharanad128862012-04-24 10:23:20 +0530117 bool reset;
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700118
119 spin_lock_irqsave(&sc->sc_pm_lock, flags);
120 if (--sc->ps_usecount != 0)
121 goto unlock;
122
Sujith Manoharanad128862012-04-24 10:23:20 +0530123 if (sc->ps_idle) {
124 ath9k_hw_setrxabort(sc->sc_ah, 1);
125 ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200126 mode = ATH9K_PM_FULL_SLEEP;
Sujith Manoharanad128862012-04-24 10:23:20 +0530127 } else if (sc->ps_enabled &&
128 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
129 PS_WAIT_FOR_CAB |
130 PS_WAIT_FOR_PSPOLL_DATA |
131 PS_WAIT_FOR_TX_ACK))) {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200132 mode = ATH9K_PM_NETWORK_SLEEP;
Sujith Manoharanad128862012-04-24 10:23:20 +0530133 } else {
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200134 goto unlock;
Sujith Manoharanad128862012-04-24 10:23:20 +0530135 }
Felix Fietkauc6c539f2011-09-14 21:24:24 +0200136
137 spin_lock(&common->cc_lock);
138 ath_hw_cycle_counters_update(common);
139 spin_unlock(&common->cc_lock);
140
Felix Fietkau1a8f0d392011-09-22 08:04:32 -0600141 ath9k_hw_setpower(sc->sc_ah, mode);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700142
143 unlock:
144 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
145}
146
Felix Fietkau9adcf442011-09-03 01:40:26 +0200147static void __ath_cancel_work(struct ath_softc *sc)
148{
149 cancel_work_sync(&sc->paprd_work);
150 cancel_work_sync(&sc->hw_check_work);
151 cancel_delayed_work_sync(&sc->tx_complete_work);
152 cancel_delayed_work_sync(&sc->hw_pll_work);
153}
154
155static void ath_cancel_work(struct ath_softc *sc)
156{
157 __ath_cancel_work(sc);
158 cancel_work_sync(&sc->hw_reset_work);
159}
160
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530161static void ath_restart_work(struct ath_softc *sc)
162{
163 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
164
165 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
166
167 if (AR_SREV_9485(sc->sc_ah) || AR_SREV_9340(sc->sc_ah))
168 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
169 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
170
171 ath_start_rx_poll(sc, 3);
172
173 if (!common->disable_ani)
174 ath_start_ani(common);
175}
176
Felix Fietkau9adcf442011-09-03 01:40:26 +0200177static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
178{
179 struct ath_hw *ah = sc->sc_ah;
180 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauceea2a52012-05-24 14:32:19 +0200181 bool ret = true;
Felix Fietkau9adcf442011-09-03 01:40:26 +0200182
183 ieee80211_stop_queues(sc->hw);
184
185 sc->hw_busy_count = 0;
186 del_timer_sync(&common->ani.timer);
Rajkumar Manoharan01e18912012-03-15 05:34:27 +0530187 del_timer_sync(&sc->rx_poll_timer);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200188
189 ath9k_debug_samp_bb_mac(sc);
190 ath9k_hw_disable_interrupts(ah);
191
Felix Fietkau9adcf442011-09-03 01:40:26 +0200192 if (!ath_stoprecv(sc))
193 ret = false;
194
Felix Fietkauceea2a52012-05-24 14:32:19 +0200195 if (!ath_drain_all_txq(sc, retry_tx))
196 ret = false;
197
Felix Fietkau9adcf442011-09-03 01:40:26 +0200198 if (!flush) {
199 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Felix Fietkau34832882011-09-14 21:23:03 +0200200 ath_rx_tasklet(sc, 1, true);
201 ath_rx_tasklet(sc, 1, false);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200202 } else {
203 ath_flushrecv(sc);
204 }
205
206 return ret;
207}
208
209static bool ath_complete_reset(struct ath_softc *sc, bool start)
210{
211 struct ath_hw *ah = sc->sc_ah;
212 struct ath_common *common = ath9k_hw_common(ah);
213
214 if (ath_startrecv(sc) != 0) {
215 ath_err(common, "Unable to restart recv logic\n");
216 return false;
217 }
218
219 ath9k_cmn_update_txpow(ah, sc->curtxpow,
220 sc->config.txpowlimit, &sc->curtxpow);
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530221
222 clear_bit(SC_OP_HW_RESET, &sc->sc_flags);
Felix Fietkau72d874c2011-10-08 20:06:19 +0200223 ath9k_hw_set_interrupts(ah);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200224 ath9k_hw_enable_interrupts(ah);
225
Sujith Manoharan4cb54fa2012-06-04 16:27:52 +0530226 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530227 if (test_bit(SC_OP_BEACONS, &sc->sc_flags))
Felix Fietkau9adcf442011-09-03 01:40:26 +0200228 ath_set_beacon(sc);
229
Sujith Manoharanaf68aba2012-06-04 20:23:43 +0530230 ath_restart_work(sc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200231 }
232
Sujith Manoharan8da07832012-06-04 20:23:49 +0530233 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3)
234 ath_ant_comb_update(sc);
Felix Fietkau43c35282011-09-03 01:40:27 +0200235
Felix Fietkau9adcf442011-09-03 01:40:26 +0200236 ieee80211_wake_queues(sc->hw);
237
238 return true;
239}
240
241static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
242 bool retry_tx)
243{
244 struct ath_hw *ah = sc->sc_ah;
245 struct ath_common *common = ath9k_hw_common(ah);
246 struct ath9k_hw_cal_data *caldata = NULL;
247 bool fastcc = true;
248 bool flush = false;
249 int r;
250
251 __ath_cancel_work(sc);
252
253 spin_lock_bh(&sc->sc_pcu_lock);
254
Sujith Manoharan4cb54fa2012-06-04 16:27:52 +0530255 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
Felix Fietkau9adcf442011-09-03 01:40:26 +0200256 fastcc = false;
257 caldata = &sc->caldata;
258 }
259
260 if (!hchan) {
261 fastcc = false;
262 flush = true;
263 hchan = ah->curchan;
264 }
265
Felix Fietkau9adcf442011-09-03 01:40:26 +0200266 if (!ath_prepare_reset(sc, retry_tx, flush))
267 fastcc = false;
268
Joe Perchesd2182b62011-12-15 14:55:53 -0800269 ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
Sujith Manoharanfeced202012-01-30 14:21:42 +0530270 hchan->channel, IS_CHAN_HT40(hchan), fastcc);
Felix Fietkau9adcf442011-09-03 01:40:26 +0200271
272 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
273 if (r) {
274 ath_err(common,
275 "Unable to reset channel, reset status %d\n", r);
276 goto out;
277 }
278
279 if (!ath_complete_reset(sc, true))
280 r = -EIO;
281
282out:
283 spin_unlock_bh(&sc->sc_pcu_lock);
284 return r;
285}
286
287
Sujithff37e332008-11-24 12:07:55 +0530288/*
289 * Set/change channels. If the channel is really being changed, it's done
290 * by reseting the chip. To accomplish this we must first cleanup any pending
291 * DMA, then restart stuff.
292*/
Mohammed Shafi Shajakhan5595f112011-05-19 18:08:57 +0530293static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200294 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530295{
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800296 int r;
Sujithff37e332008-11-24 12:07:55 +0530297
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530298 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
Sujithff37e332008-11-24 12:07:55 +0530299 return -EIO;
300
Felix Fietkau9adcf442011-09-03 01:40:26 +0200301 r = ath_reset_internal(sc, hchan, false);
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700302
Gabor Juhos39892792009-06-15 17:49:09 +0200303 return r;
Sujithff37e332008-11-24 12:07:55 +0530304}
305
Ben Greear7e1e3862011-11-03 11:33:13 -0700306static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
307 struct ieee80211_vif *vif)
Sujithff37e332008-11-24 12:07:55 +0530308{
309 struct ath_node *an;
Sujithff37e332008-11-24 12:07:55 +0530310 an = (struct ath_node *)sta->drv_priv;
311
Ben Greear7f010c92011-01-09 23:11:49 -0800312#ifdef CONFIG_ATH9K_DEBUGFS
313 spin_lock(&sc->nodes_lock);
314 list_add(&an->list, &sc->nodes);
315 spin_unlock(&sc->nodes_lock);
Felix Fietkau156369f2011-12-14 22:08:04 +0100316#endif
Ben Greear7f010c92011-01-09 23:11:49 -0800317 an->sta = sta;
Ben Greear7e1e3862011-11-03 11:33:13 -0700318 an->vif = vif;
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530319
Sujith Manoharana4d63672012-03-27 10:08:55 +0530320 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +0530321 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530322 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530323 sta->ht_cap.ampdu_factor);
324 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
325 }
Sujithff37e332008-11-24 12:07:55 +0530326}
327
328static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
329{
330 struct ath_node *an = (struct ath_node *)sta->drv_priv;
331
Ben Greear7f010c92011-01-09 23:11:49 -0800332#ifdef CONFIG_ATH9K_DEBUGFS
333 spin_lock(&sc->nodes_lock);
334 list_del(&an->list);
335 spin_unlock(&sc->nodes_lock);
336 an->sta = NULL;
337#endif
338
Sujith Manoharana4d63672012-03-27 10:08:55 +0530339 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujithff37e332008-11-24 12:07:55 +0530340 ath_tx_node_cleanup(sc, an);
341}
342
Sujith55624202010-01-08 10:36:02 +0530343void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530344{
345 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700346 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700347 struct ath_common *common = ath9k_hw_common(ah);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530348 unsigned long flags;
Sujith17d79042009-02-09 13:27:03 +0530349 u32 status = sc->intrstatus;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400350 u32 rxmask;
Sujithff37e332008-11-24 12:07:55 +0530351
Felix Fietkaue3927002011-09-14 21:23:01 +0200352 ath9k_ps_wakeup(sc);
353 spin_lock(&sc->sc_pcu_lock);
354
Rajkumar Manoharana4d86d92011-05-20 17:52:10 +0530355 if ((status & ATH9K_INT_FATAL) ||
356 (status & ATH9K_INT_BB_WATCHDOG)) {
Felix Fietkau030d6292011-10-07 02:28:13 +0200357#ifdef CONFIG_ATH9K_DEBUGFS
358 enum ath_reset_type type;
359
360 if (status & ATH9K_INT_FATAL)
361 type = RESET_TYPE_FATAL_INT;
362 else
363 type = RESET_TYPE_BB_WATCHDOG;
364
365 RESET_STAT_INC(sc, type);
366#endif
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530367 set_bit(SC_OP_HW_RESET, &sc->sc_flags);
Felix Fietkau236de512011-09-03 01:40:25 +0200368 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
Felix Fietkaue3927002011-09-14 21:23:01 +0200369 goto out;
Sujithff37e332008-11-24 12:07:55 +0530370 }
371
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530372 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530373 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
374 /*
375 * TSF sync does not look correct; remain awake to sync with
376 * the next Beacon.
377 */
Joe Perchesd2182b62011-12-15 14:55:53 -0800378 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
Rajkumar Manoharane8fe7332011-08-05 18:59:41 +0530379 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530380 }
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530381 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Rajkumar Manoharan4105f802011-05-06 18:27:47 +0530382
Felix Fietkaub5c804752010-04-15 17:38:48 -0400383 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
384 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
385 ATH9K_INT_RXORN);
386 else
387 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
388
389 if (status & rxmask) {
Felix Fietkaub5c804752010-04-15 17:38:48 -0400390 /* Check for high priority Rx first */
391 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
392 (status & ATH9K_INT_RXHP))
393 ath_rx_tasklet(sc, 0, true);
394
395 ath_rx_tasklet(sc, 0, false);
Sujith063d8be2009-03-30 15:28:49 +0530396 }
397
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400398 if (status & ATH9K_INT_TX) {
399 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
400 ath_tx_edma_tasklet(sc);
401 else
402 ath_tx_tasklet(sc);
403 }
Sujith063d8be2009-03-30 15:28:49 +0530404
Sujith Manoharan56ca0db2012-02-22 12:40:32 +0530405 ath9k_btcoex_handle_interrupt(sc, status);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530406
Felix Fietkaue3927002011-09-14 21:23:01 +0200407out:
Sujithff37e332008-11-24 12:07:55 +0530408 /* re-enable hardware interrupt */
Felix Fietkau4df30712010-11-08 20:54:47 +0100409 ath9k_hw_enable_interrupts(ah);
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700410
Senthil Balasubramanian52671e42010-12-23 21:06:57 +0530411 spin_unlock(&sc->sc_pcu_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400412 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530413}
414
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100415irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530416{
Sujith063d8be2009-03-30 15:28:49 +0530417#define SCHED_INTR ( \
418 ATH9K_INT_FATAL | \
Rajkumar Manoharana4d86d92011-05-20 17:52:10 +0530419 ATH9K_INT_BB_WATCHDOG | \
Sujith063d8be2009-03-30 15:28:49 +0530420 ATH9K_INT_RXORN | \
421 ATH9K_INT_RXEOL | \
422 ATH9K_INT_RX | \
Felix Fietkaub5c804752010-04-15 17:38:48 -0400423 ATH9K_INT_RXLP | \
424 ATH9K_INT_RXHP | \
Sujith063d8be2009-03-30 15:28:49 +0530425 ATH9K_INT_TX | \
426 ATH9K_INT_BMISS | \
427 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530428 ATH9K_INT_TSFOOR | \
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530429 ATH9K_INT_GENTIMER | \
430 ATH9K_INT_MCI)
Sujith063d8be2009-03-30 15:28:49 +0530431
Sujithff37e332008-11-24 12:07:55 +0530432 struct ath_softc *sc = dev;
Sujithcbe61d8a2009-02-09 13:27:12 +0530433 struct ath_hw *ah = sc->sc_ah;
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200434 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530435 enum ath9k_int status;
436 bool sched = false;
437
Sujith063d8be2009-03-30 15:28:49 +0530438 /*
439 * The hardware is not ready/present, don't
440 * touch anything. Note this can happen early
441 * on if the IRQ is shared.
442 */
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530443 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
Sujith063d8be2009-03-30 15:28:49 +0530444 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530445
Sujith063d8be2009-03-30 15:28:49 +0530446 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530447
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400448 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530449 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530450
Sujith Manoharanb74713d2012-06-04 20:24:01 +0530451 if(test_bit(SC_OP_HW_RESET, &sc->sc_flags))
452 return IRQ_HANDLED;
453
Sujith063d8be2009-03-30 15:28:49 +0530454 /*
455 * Figure out the reason(s) for the interrupt. Note
456 * that the hal returns a pseudo-ISR that may include
457 * bits we haven't explicitly enabled so we mask the
458 * value to insure we only process bits we requested.
459 */
460 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
Pavel Roskin30691682010-03-31 18:05:31 -0400461 status &= ah->imask; /* discard unasked-for bits */
Sujith063d8be2009-03-30 15:28:49 +0530462
463 /*
464 * If there are no status bits set, then this interrupt was not
465 * for me (should have been caught above).
466 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400467 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530468 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530469
470 /* Cache the status */
471 sc->intrstatus = status;
472
473 if (status & SCHED_INTR)
474 sched = true;
475
476 /*
477 * If a FATAL or RXORN interrupt is received, we have to reset the
478 * chip immediately.
479 */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400480 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
481 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
Sujith063d8be2009-03-30 15:28:49 +0530482 goto chip_reset;
483
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400484 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
485 (status & ATH9K_INT_BB_WATCHDOG)) {
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200486
487 spin_lock(&common->cc_lock);
488 ath_hw_cycle_counters_update(common);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400489 ar9003_hw_bb_watchdog_dbg_info(ah);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200490 spin_unlock(&common->cc_lock);
491
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400492 goto chip_reset;
493 }
494
Sujith063d8be2009-03-30 15:28:49 +0530495 if (status & ATH9K_INT_SWBA)
496 tasklet_schedule(&sc->bcon_tasklet);
497
498 if (status & ATH9K_INT_TXURN)
499 ath9k_hw_updatetxtriglevel(ah, true);
500
Rajkumar Manoharan0682c9b2011-08-13 10:28:09 +0530501 if (status & ATH9K_INT_RXEOL) {
502 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
Felix Fietkau72d874c2011-10-08 20:06:19 +0200503 ath9k_hw_set_interrupts(ah);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400504 }
505
Sujith063d8be2009-03-30 15:28:49 +0530506 if (status & ATH9K_INT_MIB) {
507 /*
508 * Disable interrupts until we service the MIB
509 * interrupt; otherwise it will continue to
510 * fire.
511 */
Felix Fietkau4df30712010-11-08 20:54:47 +0100512 ath9k_hw_disable_interrupts(ah);
Sujith063d8be2009-03-30 15:28:49 +0530513 /*
514 * Let the hal handle the event. We assume
515 * it will clear whatever condition caused
516 * the interrupt.
517 */
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200518 spin_lock(&common->cc_lock);
Felix Fietkaubfc472b2010-10-04 20:09:48 +0200519 ath9k_hw_proc_mib_event(ah);
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200520 spin_unlock(&common->cc_lock);
Felix Fietkau4df30712010-11-08 20:54:47 +0100521 ath9k_hw_enable_interrupts(ah);
Sujith063d8be2009-03-30 15:28:49 +0530522 }
523
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400524 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
525 if (status & ATH9K_INT_TIM_TIMER) {
Luis R. Rodriguezff9f0b62010-12-07 15:13:22 -0800526 if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
527 goto chip_reset;
Sujith063d8be2009-03-30 15:28:49 +0530528 /* Clear RxAbort bit so that we can
529 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700530 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530531 spin_lock(&sc->sc_pm_lock);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400532 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530533 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530534 spin_unlock(&sc->sc_pm_lock);
Sujith063d8be2009-03-30 15:28:49 +0530535 }
Sujith063d8be2009-03-30 15:28:49 +0530536
537chip_reset:
538
Sujith817e11d2008-12-07 21:42:44 +0530539 ath_debug_stat_interrupt(sc, status);
540
Sujithff37e332008-11-24 12:07:55 +0530541 if (sched) {
Felix Fietkau4df30712010-11-08 20:54:47 +0100542 /* turn off every interrupt */
543 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530544 tasklet_schedule(&sc->intr_tq);
545 }
546
547 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530548
549#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530550}
551
Felix Fietkau236de512011-09-03 01:40:25 +0200552static int ath_reset(struct ath_softc *sc, bool retry_tx)
Sujithff37e332008-11-24 12:07:55 +0530553{
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800554 int r;
Sujithff37e332008-11-24 12:07:55 +0530555
Felix Fietkau783cd012011-01-21 18:52:38 +0100556 ath9k_ps_wakeup(sc);
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700557
Felix Fietkau9adcf442011-09-03 01:40:26 +0200558 r = ath_reset_internal(sc, NULL, retry_tx);
Sujithff37e332008-11-24 12:07:55 +0530559
560 if (retry_tx) {
561 int i;
562 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
563 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +0530564 spin_lock_bh(&sc->tx.txq[i].axq_lock);
565 ath_txq_schedule(sc, &sc->tx.txq[i]);
566 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +0530567 }
568 }
569 }
570
Felix Fietkau783cd012011-01-21 18:52:38 +0100571 ath9k_ps_restore(sc);
Sujith2ab81d42009-12-14 16:34:56 +0530572
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800573 return r;
Sujithff37e332008-11-24 12:07:55 +0530574}
575
Felix Fietkau236de512011-09-03 01:40:25 +0200576void ath_reset_work(struct work_struct *work)
577{
578 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
579
Felix Fietkau236de512011-09-03 01:40:25 +0200580 ath_reset(sc, true);
Felix Fietkau236de512011-09-03 01:40:25 +0200581}
582
Sujithff37e332008-11-24 12:07:55 +0530583/**********************/
584/* mac80211 callbacks */
585/**********************/
586
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700587static int ath9k_start(struct ieee80211_hw *hw)
588{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100589 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700590 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700591 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700592 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +0530593 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530594 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595
Joe Perchesd2182b62011-12-15 14:55:53 -0800596 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -0800597 "Starting driver with initial channel: %d MHz\n",
598 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700599
Felix Fietkauf62d8162011-03-25 17:43:41 +0100600 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +0530601 mutex_lock(&sc->mutex);
602
Rajkumar Manoharanc344c9c2011-01-31 23:47:43 +0530603 init_channel = ath9k_cmn_get_curchannel(hw, ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700604
Sujithff37e332008-11-24 12:07:55 +0530605 /* Reset SERDES registers */
Stanislaw Gruszka84c87dc2011-08-05 13:10:32 +0200606 ath9k_hw_configpcipowersave(ah, false);
Sujithff37e332008-11-24 12:07:55 +0530607
608 /*
609 * The basic interface to setting the hardware in a good
610 * state is ``reset''. On return the hardware is known to
611 * be powered up and with interrupts disabled. This must
612 * be followed by initialization of the appropriate bits
613 * and then setup of the interrupt mask.
614 */
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700615 spin_lock_bh(&sc->sc_pcu_lock);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100616
617 atomic_set(&ah->intr_ref_cnt, -1);
618
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200619 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800620 if (r) {
Joe Perches38002762010-12-02 19:12:36 -0800621 ath_err(common,
622 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
623 r, curchan->center_freq);
Luis R. Rodriguez4bdd1e92010-10-26 15:27:24 -0700624 spin_unlock_bh(&sc->sc_pcu_lock);
Sujith141b38b2009-02-04 08:10:07 +0530625 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700626 }
Sujithff37e332008-11-24 12:07:55 +0530627
Sujithff37e332008-11-24 12:07:55 +0530628 /* Setup our intr mask. */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400629 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
630 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
631 ATH9K_INT_GLOBAL;
632
633 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400634 ah->imask |= ATH9K_INT_RXHP |
635 ATH9K_INT_RXLP |
636 ATH9K_INT_BB_WATCHDOG;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400637 else
638 ah->imask |= ATH9K_INT_RX;
Sujithff37e332008-11-24 12:07:55 +0530639
Felix Fietkau364734f2010-09-14 20:22:44 +0200640 ah->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +0530641
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700642 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Pavel Roskin30691682010-03-31 18:05:31 -0400643 ah->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +0530644
Sujith Manoharane270e772012-06-04 16:27:19 +0530645 ath_mci_enable(sc);
Mohammed Shafi Shajakhan40dc5392011-11-30 10:41:18 +0530646
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530647 clear_bit(SC_OP_INVALID, &sc->sc_flags);
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +0530648 sc->sc_ah->is_monitoring = false;
Sujithff37e332008-11-24 12:07:55 +0530649
Felix Fietkau9adcf442011-09-03 01:40:26 +0200650 if (!ath_complete_reset(sc, false)) {
651 r = -EIO;
652 spin_unlock_bh(&sc->sc_pcu_lock);
653 goto mutex_unlock;
654 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700655
Felix Fietkauc0c11742011-11-16 13:08:41 +0100656 if (ah->led_pin >= 0) {
657 ath9k_hw_cfg_output(ah, ah->led_pin,
658 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
659 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
660 }
661
662 /*
663 * Reset key cache to sane defaults (all entries cleared) instead of
664 * semi-random values after suspend/resume.
665 */
666 ath9k_cmn_init_crypto(sc->sc_ah);
667
Felix Fietkau9adcf442011-09-03 01:40:26 +0200668 spin_unlock_bh(&sc->sc_pcu_lock);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -0400669
Sujith Manoharandf198b12012-02-22 12:40:27 +0530670 ath9k_start_btcoex(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530671
Vasanthakumar Thiagarajan8060e162010-12-06 04:27:42 -0800672 if (ah->caps.pcie_lcr_extsync_en && common->bus_ops->extn_synch_en)
673 common->bus_ops->extn_synch_en(common);
674
Sujith141b38b2009-02-04 08:10:07 +0530675mutex_unlock:
676 mutex_unlock(&sc->mutex);
677
Felix Fietkauf62d8162011-03-25 17:43:41 +0100678 ath9k_ps_restore(sc);
679
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800680 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700681}
682
Johannes Berg7bb456832011-02-24 14:42:06 +0100683static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100685 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700686 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +0530687 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +0100688 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530689 unsigned long flags;
Sujith528f0c62008-10-29 10:14:26 +0530690
Gabor Juhos96148322009-07-24 17:27:21 +0200691 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +0300692 /*
693 * mac80211 does not set PM field for normal data frames, so we
694 * need to update that based on the current PS mode.
695 */
696 if (ieee80211_is_data(hdr->frame_control) &&
697 !ieee80211_is_nullfunc(hdr->frame_control) &&
698 !ieee80211_has_pm(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800699 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800700 "Add PM=1 for a TX frame while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +0300701 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
702 }
703 }
704
Sujith Manoharanad128862012-04-24 10:23:20 +0530705 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300706 /*
707 * We are using PS-Poll and mac80211 can request TX while in
708 * power save mode. Need to wake up hardware for the TX to be
709 * completed and if needed, also for RX of buffered frames.
710 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300711 ath9k_ps_wakeup(sc);
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530712 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -0700713 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
714 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300715 if (ieee80211_is_pspoll(hdr->frame_control)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800716 ath_dbg(common, PS,
Joe Perches226afe62010-12-02 19:12:37 -0800717 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +0530718 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300719 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -0800720 ath_dbg(common, PS, "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +0530721 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300722 }
723 /*
724 * The actual restore operation will happen only after
Sujith Manoharanad128862012-04-24 10:23:20 +0530725 * the ps_flags bit is cleared. We are just dropping
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300726 * the ps_usecount here.
727 */
Sujith Manoharan07c15a32012-06-04 20:24:07 +0530728 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +0300729 ath9k_ps_restore(sc);
730 }
731
Sujith Manoharanad128862012-04-24 10:23:20 +0530732 /*
733 * Cannot tx while the hardware is in full sleep, it first needs a full
734 * chip reset to recover from that
735 */
736 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
737 ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
738 goto exit;
739 }
740
Sujith528f0c62008-10-29 10:14:26 +0530741 memset(&txctl, 0, sizeof(struct ath_tx_control));
Felix Fietkau066dae92010-11-07 14:59:39 +0100742 txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
Sujith528f0c62008-10-29 10:14:26 +0530743
Joe Perchesd2182b62011-12-15 14:55:53 -0800744 ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745
Jouni Malinenc52f33d2009-03-03 19:23:29 +0200746 if (ath_tx_start(hw, skb, &txctl) != 0) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800747 ath_dbg(common, XMIT, "TX failed\n");
Ben Greeara5a0bca2012-04-03 09:16:55 -0700748 TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
Sujith528f0c62008-10-29 10:14:26 +0530749 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 }
751
Johannes Berg7bb456832011-02-24 14:42:06 +0100752 return;
Sujith528f0c62008-10-29 10:14:26 +0530753exit:
754 dev_kfree_skb_any(skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700755}
756
757static void ath9k_stop(struct ieee80211_hw *hw)
758{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100759 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700760 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700761 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100762 bool prev_idle;
Sujith9c84b792008-10-29 10:17:13 +0530763
Sujith4c483812009-08-18 10:51:52 +0530764 mutex_lock(&sc->mutex);
765
Felix Fietkau9adcf442011-09-03 01:40:26 +0200766 ath_cancel_work(sc);
Rajkumar Manoharan01e18912012-03-15 05:34:27 +0530767 del_timer_sync(&sc->rx_poll_timer);
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -0700768
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530769 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800770 ath_dbg(common, ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +0530771 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +0530772 return;
773 }
774
Sujith3867cf62009-12-23 20:03:27 -0500775 /* Ensure HW is awake when we try to shut it down. */
776 ath9k_ps_wakeup(sc);
777
Sujith Manoharandf198b12012-02-22 12:40:27 +0530778 ath9k_stop_btcoex(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +0530779
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700780 spin_lock_bh(&sc->sc_pcu_lock);
781
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100782 /* prevent tasklets to enable interrupts once we disable them */
783 ah->imask &= ~ATH9K_INT_GLOBAL;
784
Sujithff37e332008-11-24 12:07:55 +0530785 /* make sure h/w will not generate any interrupt
786 * before setting the invalid flag. */
Felix Fietkau4df30712010-11-08 20:54:47 +0100787 ath9k_hw_disable_interrupts(ah);
Sujithff37e332008-11-24 12:07:55 +0530788
Luis R. Rodriguez6a6733f2010-10-26 15:27:25 -0700789 spin_unlock_bh(&sc->sc_pcu_lock);
790
Stanislaw Gruszka203043f2011-01-25 14:08:40 +0100791 /* we can now sync irq and kill any running tasklets, since we already
792 * disabled interrupts and not holding a spin lock */
793 synchronize_irq(sc->irq);
794 tasklet_kill(&sc->intr_tq);
795 tasklet_kill(&sc->bcon_tasklet);
796
Felix Fietkauc0c11742011-11-16 13:08:41 +0100797 prev_idle = sc->ps_idle;
798 sc->ps_idle = true;
799
800 spin_lock_bh(&sc->sc_pcu_lock);
801
802 if (ah->led_pin >= 0) {
803 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
804 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
805 }
806
807 ath_prepare_reset(sc, false, true);
808
809 if (sc->rx.frag) {
810 dev_kfree_skb_any(sc->rx.frag);
811 sc->rx.frag = NULL;
812 }
813
814 if (!ah->curchan)
815 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
816
817 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
818 ath9k_hw_phy_disable(ah);
819
820 ath9k_hw_configpcipowersave(ah, true);
821
822 spin_unlock_bh(&sc->sc_pcu_lock);
823
Sujith3867cf62009-12-23 20:03:27 -0500824 ath9k_ps_restore(sc);
825
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530826 set_bit(SC_OP_INVALID, &sc->sc_flags);
Felix Fietkauc0c11742011-11-16 13:08:41 +0100827 sc->ps_idle = prev_idle;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700828
Sujith141b38b2009-02-04 08:10:07 +0530829 mutex_unlock(&sc->mutex);
830
Joe Perchesd2182b62011-12-15 14:55:53 -0800831 ath_dbg(common, CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700832}
833
Ben Greear48014162011-01-15 19:13:48 +0000834bool ath9k_uses_beacons(int type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700835{
Ben Greear48014162011-01-15 19:13:48 +0000836 switch (type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200837 case NL80211_IFTYPE_AP:
Ben Greear48014162011-01-15 19:13:48 +0000838 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -0400839 case NL80211_IFTYPE_MESH_POINT:
Ben Greear48014162011-01-15 19:13:48 +0000840 return true;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700841 default:
Ben Greear48014162011-01-15 19:13:48 +0000842 return false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700843 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700844}
845
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +0530846static void ath9k_reclaim_beacon(struct ath_softc *sc,
847 struct ieee80211_vif *vif)
848{
849 struct ath_vif *avp = (void *)vif->drv_priv;
850
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +0530851 ath9k_set_beaconing_status(sc, false);
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +0530852 ath_beacon_return(sc, avp);
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +0530853 ath9k_set_beaconing_status(sc, true);
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +0530854}
855
Ben Greear48014162011-01-15 19:13:48 +0000856static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
857{
858 struct ath9k_vif_iter_data *iter_data = data;
859 int i;
860
861 if (iter_data->hw_macaddr)
862 for (i = 0; i < ETH_ALEN; i++)
863 iter_data->mask[i] &=
864 ~(iter_data->hw_macaddr[i] ^ mac[i]);
865
866 switch (vif->type) {
867 case NL80211_IFTYPE_AP:
868 iter_data->naps++;
869 break;
870 case NL80211_IFTYPE_STATION:
871 iter_data->nstations++;
872 break;
873 case NL80211_IFTYPE_ADHOC:
874 iter_data->nadhocs++;
875 break;
876 case NL80211_IFTYPE_MESH_POINT:
877 iter_data->nmeshes++;
878 break;
879 case NL80211_IFTYPE_WDS:
880 iter_data->nwds++;
881 break;
882 default:
Ben Greear48014162011-01-15 19:13:48 +0000883 break;
884 }
885}
886
887/* Called with sc->mutex held. */
888void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
889 struct ieee80211_vif *vif,
890 struct ath9k_vif_iter_data *iter_data)
891{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100892 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000893 struct ath_hw *ah = sc->sc_ah;
894 struct ath_common *common = ath9k_hw_common(ah);
Ben Greear48014162011-01-15 19:13:48 +0000895
896 /*
897 * Use the hardware MAC address as reference, the hardware uses it
898 * together with the BSSID mask when matching addresses.
899 */
900 memset(iter_data, 0, sizeof(*iter_data));
901 iter_data->hw_macaddr = common->macaddr;
902 memset(&iter_data->mask, 0xff, ETH_ALEN);
903
904 if (vif)
905 ath9k_vif_iter(iter_data, vif->addr, vif);
906
907 /* Get list of all active MAC addresses */
Ben Greear48014162011-01-15 19:13:48 +0000908 ieee80211_iterate_active_interfaces_atomic(sc->hw, ath9k_vif_iter,
909 iter_data);
Ben Greear48014162011-01-15 19:13:48 +0000910}
911
912/* Called with sc->mutex held. */
913static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
914 struct ieee80211_vif *vif)
915{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100916 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000917 struct ath_hw *ah = sc->sc_ah;
918 struct ath_common *common = ath9k_hw_common(ah);
919 struct ath9k_vif_iter_data iter_data;
920
921 ath9k_calculate_iter_data(hw, vif, &iter_data);
922
923 /* Set BSSID mask. */
924 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
925 ath_hw_setbssidmask(common);
926
927 /* Set op-mode & TSF */
928 if (iter_data.naps > 0) {
929 ath9k_hw_set_tsfadjust(ah, 1);
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530930 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
Ben Greear48014162011-01-15 19:13:48 +0000931 ah->opmode = NL80211_IFTYPE_AP;
932 } else {
933 ath9k_hw_set_tsfadjust(ah, 0);
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530934 clear_bit(SC_OP_TSF_RESET, &sc->sc_flags);
Ben Greear48014162011-01-15 19:13:48 +0000935
Javier Cardonafd5999c2011-05-03 16:57:19 -0700936 if (iter_data.nmeshes)
937 ah->opmode = NL80211_IFTYPE_MESH_POINT;
938 else if (iter_data.nwds)
Ben Greear48014162011-01-15 19:13:48 +0000939 ah->opmode = NL80211_IFTYPE_AP;
940 else if (iter_data.nadhocs)
941 ah->opmode = NL80211_IFTYPE_ADHOC;
942 else
943 ah->opmode = NL80211_IFTYPE_STATION;
944 }
945
946 /*
947 * Enable MIB interrupts when there are hardware phy counters.
948 */
949 if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) {
950 if (ah->config.enable_ani)
951 ah->imask |= ATH9K_INT_MIB;
952 ah->imask |= ATH9K_INT_TSFOOR;
953 } else {
954 ah->imask &= ~ATH9K_INT_MIB;
955 ah->imask &= ~ATH9K_INT_TSFOOR;
956 }
957
Felix Fietkau72d874c2011-10-08 20:06:19 +0200958 ath9k_hw_set_interrupts(ah);
Ben Greear48014162011-01-15 19:13:48 +0000959
960 /* Set up ANI */
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +0530961 if (iter_data.naps > 0) {
Rajkumar Manoharan729da3902011-05-09 19:11:29 +0530962 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530963
964 if (!common->disable_ani) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530965 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530966 ath_start_ani(common);
967 }
968
Rajkumar Manoharanf60c49b2011-04-08 17:06:25 +0530969 } else {
Sujith Manoharan781b14a2012-06-04 20:23:55 +0530970 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Rajkumar Manoharanf60c49b2011-04-08 17:06:25 +0530971 del_timer_sync(&common->ani.timer);
Ben Greear48014162011-01-15 19:13:48 +0000972 }
973}
974
975/* Called with sc->mutex held, vif counts set up properly. */
976static void ath9k_do_vif_add_setup(struct ieee80211_hw *hw,
977 struct ieee80211_vif *vif)
978{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100979 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000980
981 ath9k_calculate_summary_state(hw, vif);
982
983 if (ath9k_uses_beacons(vif->type)) {
Rajkumar Manoharaned2578c2012-04-19 19:13:51 +0530984 /* Reserve a beacon slot for the vif */
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +0530985 ath9k_set_beaconing_status(sc, false);
Rajkumar Manoharaned2578c2012-04-19 19:13:51 +0530986 ath_beacon_alloc(sc, vif);
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +0530987 ath9k_set_beaconing_status(sc, true);
Ben Greear48014162011-01-15 19:13:48 +0000988 }
989}
990
Ben Greear48014162011-01-15 19:13:48 +0000991static int ath9k_add_interface(struct ieee80211_hw *hw,
992 struct ieee80211_vif *vif)
993{
Felix Fietkau9ac586152011-01-24 19:23:18 +0100994 struct ath_softc *sc = hw->priv;
Ben Greear48014162011-01-15 19:13:48 +0000995 struct ath_hw *ah = sc->sc_ah;
996 struct ath_common *common = ath9k_hw_common(ah);
Ben Greear48014162011-01-15 19:13:48 +0000997 int ret = 0;
998
Felix Fietkau96f372c2011-04-07 19:07:17 +0200999 ath9k_ps_wakeup(sc);
Ben Greear48014162011-01-15 19:13:48 +00001000 mutex_lock(&sc->mutex);
1001
1002 switch (vif->type) {
1003 case NL80211_IFTYPE_STATION:
1004 case NL80211_IFTYPE_WDS:
1005 case NL80211_IFTYPE_ADHOC:
1006 case NL80211_IFTYPE_AP:
1007 case NL80211_IFTYPE_MESH_POINT:
1008 break;
1009 default:
1010 ath_err(common, "Interface type %d not yet supported\n",
1011 vif->type);
1012 ret = -EOPNOTSUPP;
1013 goto out;
1014 }
1015
1016 if (ath9k_uses_beacons(vif->type)) {
1017 if (sc->nbcnvifs >= ATH_BCBUF) {
1018 ath_err(common, "Not enough beacon buffers when adding"
1019 " new interface of type: %i\n",
1020 vif->type);
1021 ret = -ENOBUFS;
1022 goto out;
1023 }
1024 }
1025
Rajkumar Manoharan59575d12011-04-04 22:56:16 +05301026 if ((ah->opmode == NL80211_IFTYPE_ADHOC) ||
1027 ((vif->type == NL80211_IFTYPE_ADHOC) &&
1028 sc->nvifs > 0)) {
Ben Greear48014162011-01-15 19:13:48 +00001029 ath_err(common, "Cannot create ADHOC interface when other"
1030 " interfaces already exist.\n");
1031 ret = -EINVAL;
1032 goto out;
1033 }
1034
Joe Perchesd2182b62011-12-15 14:55:53 -08001035 ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
Ben Greear48014162011-01-15 19:13:48 +00001036
Ben Greear48014162011-01-15 19:13:48 +00001037 sc->nvifs++;
1038
1039 ath9k_do_vif_add_setup(hw, vif);
1040out:
1041 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001042 ath9k_ps_restore(sc);
Ben Greear48014162011-01-15 19:13:48 +00001043 return ret;
1044}
1045
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301046static int ath9k_change_interface(struct ieee80211_hw *hw,
1047 struct ieee80211_vif *vif,
1048 enum nl80211_iftype new_type,
1049 bool p2p)
1050{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001051 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301052 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Dan Carpenter6dab55b2010-12-21 06:59:06 +03001053 int ret = 0;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301054
Joe Perchesd2182b62011-12-15 14:55:53 -08001055 ath_dbg(common, CONFIG, "Change Interface\n");
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301056 mutex_lock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001057 ath9k_ps_wakeup(sc);
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301058
Ben Greear48014162011-01-15 19:13:48 +00001059 /* See if new interface type is valid. */
1060 if ((new_type == NL80211_IFTYPE_ADHOC) &&
1061 (sc->nvifs > 1)) {
1062 ath_err(common, "When using ADHOC, it must be the only"
1063 " interface.\n");
1064 ret = -EINVAL;
1065 goto out;
1066 }
1067
1068 if (ath9k_uses_beacons(new_type) &&
1069 !ath9k_uses_beacons(vif->type)) {
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301070 if (sc->nbcnvifs >= ATH_BCBUF) {
1071 ath_err(common, "No beacon slot available\n");
Dan Carpenter6dab55b2010-12-21 06:59:06 +03001072 ret = -ENOBUFS;
1073 goto out;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301074 }
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301075 }
Ben Greear48014162011-01-15 19:13:48 +00001076
1077 /* Clean up old vif stuff */
1078 if (ath9k_uses_beacons(vif->type))
1079 ath9k_reclaim_beacon(sc, vif);
1080
1081 /* Add new settings */
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301082 vif->type = new_type;
1083 vif->p2p = p2p;
1084
Ben Greear48014162011-01-15 19:13:48 +00001085 ath9k_do_vif_add_setup(hw, vif);
Dan Carpenter6dab55b2010-12-21 06:59:06 +03001086out:
Felix Fietkau96f372c2011-04-07 19:07:17 +02001087 ath9k_ps_restore(sc);
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301088 mutex_unlock(&sc->mutex);
Dan Carpenter6dab55b2010-12-21 06:59:06 +03001089 return ret;
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301090}
1091
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001092static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001093 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001094{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001095 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001096 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001097
Joe Perchesd2182b62011-12-15 14:55:53 -08001098 ath_dbg(common, CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001099
Felix Fietkau96f372c2011-04-07 19:07:17 +02001100 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301101 mutex_lock(&sc->mutex);
1102
Ben Greear48014162011-01-15 19:13:48 +00001103 sc->nvifs--;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001104
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001105 /* Reclaim beacon resources */
Ben Greear48014162011-01-15 19:13:48 +00001106 if (ath9k_uses_beacons(vif->type))
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05301107 ath9k_reclaim_beacon(sc, vif);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001108
Ben Greear48014162011-01-15 19:13:48 +00001109 ath9k_calculate_summary_state(hw, NULL);
Sujith141b38b2009-02-04 08:10:07 +05301110
1111 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001112 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001113}
1114
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301115static void ath9k_enable_ps(struct ath_softc *sc)
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301116{
Pavel Roskin30691682010-03-31 18:05:31 -04001117 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301118 struct ath_common *common = ath9k_hw_common(ah);
Pavel Roskin30691682010-03-31 18:05:31 -04001119
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301120 sc->ps_enabled = true;
Pavel Roskin30691682010-03-31 18:05:31 -04001121 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1122 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1123 ah->imask |= ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001124 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301125 }
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001126 ath9k_hw_setrxabort(ah, 1);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301127 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301128 ath_dbg(common, PS, "PowerSave enabled\n");
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301129}
1130
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301131static void ath9k_disable_ps(struct ath_softc *sc)
1132{
1133 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanad128862012-04-24 10:23:20 +05301134 struct ath_common *common = ath9k_hw_common(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301135
1136 sc->ps_enabled = false;
1137 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1138 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1139 ath9k_hw_setrxabort(ah, 0);
1140 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1141 PS_WAIT_FOR_CAB |
1142 PS_WAIT_FOR_PSPOLL_DATA |
1143 PS_WAIT_FOR_TX_ACK);
1144 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1145 ah->imask &= ~ATH9K_INT_TIM_TIMER;
Felix Fietkau72d874c2011-10-08 20:06:19 +02001146 ath9k_hw_set_interrupts(ah);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301147 }
1148 }
Sujith Manoharanad128862012-04-24 10:23:20 +05301149 ath_dbg(common, PS, "PowerSave disabled\n");
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301150}
1151
Johannes Berge8975582008-10-09 12:18:51 +02001152static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001153{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001154 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001155 struct ath_hw *ah = sc->sc_ah;
1156 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berge8975582008-10-09 12:18:51 +02001157 struct ieee80211_conf *conf = &hw->conf;
Felix Fietkau75600ab2012-04-12 20:36:31 +02001158 bool reset_channel = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001159
Felix Fietkauc0c11742011-11-16 13:08:41 +01001160 ath9k_ps_wakeup(sc);
Sujithaa33de02008-12-18 11:40:16 +05301161 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301162
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001163 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Felix Fietkau7545daf2011-01-24 19:23:16 +01001164 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001165 if (sc->ps_idle)
1166 ath_cancel_work(sc);
Felix Fietkau75600ab2012-04-12 20:36:31 +02001167 else
1168 /*
1169 * The chip needs a reset to properly wake up from
1170 * full sleep
1171 */
1172 reset_channel = ah->chip_fullsleep;
Felix Fietkaudaa1b6e2011-11-16 13:08:43 +01001173 }
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001174
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001175 /*
1176 * We just prepare to enable PS. We have to wait until our AP has
1177 * ACK'd our null data frame to disable RX otherwise we'll ignore
1178 * those ACKs and end up retransmitting the same null data frames.
1179 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1180 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301181 if (changed & IEEE80211_CONF_CHANGE_PS) {
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001182 unsigned long flags;
1183 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301184 if (conf->flags & IEEE80211_CONF_PS)
1185 ath9k_enable_ps(sc);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301186 else
1187 ath9k_disable_ps(sc);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001188 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301189 }
1190
Sujith199afd92010-01-08 10:36:13 +05301191 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1192 if (conf->flags & IEEE80211_CONF_MONITOR) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001193 ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301194 sc->sc_ah->is_monitoring = true;
1195 } else {
Joe Perchesd2182b62011-12-15 14:55:53 -08001196 ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301197 sc->sc_ah->is_monitoring = false;
Sujith199afd92010-01-08 10:36:13 +05301198 }
1199 }
1200
Felix Fietkau75600ab2012-04-12 20:36:31 +02001201 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
Sujith99405f92008-11-24 12:08:35 +05301202 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001203 int pos = curchan->hw_value;
Felix Fietkau34300982010-10-10 18:21:52 +02001204 int old_pos = -1;
1205 unsigned long flags;
1206
1207 if (ah->curchan)
1208 old_pos = ah->curchan - &ah->channels[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001209
Joe Perchesd2182b62011-12-15 14:55:53 -08001210 ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
Ben Greear8c79a612011-02-07 13:44:33 -08001211 curchan->center_freq, conf->channel_type);
Johannes Bergae5eb022008-10-14 16:58:37 +02001212
Felix Fietkau34300982010-10-10 18:21:52 +02001213 /* update survey stats for the old channel before switching */
1214 spin_lock_irqsave(&common->cc_lock, flags);
1215 ath_update_survey_stats(sc);
1216 spin_unlock_irqrestore(&common->cc_lock, flags);
1217
1218 /*
Rajkumar Manoharane338a852011-08-13 10:28:17 +05301219 * Preserve the current channel values, before updating
1220 * the same channel
1221 */
Rajkumar Manoharan1a19f772012-01-09 15:37:53 +05301222 if (ah->curchan && (old_pos == pos))
1223 ath9k_hw_getnf(ah, ah->curchan);
Rajkumar Manoharane338a852011-08-13 10:28:17 +05301224
1225 ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
1226 curchan, conf->channel_type);
1227
1228 /*
Felix Fietkau34300982010-10-10 18:21:52 +02001229 * If the operating channel changes, change the survey in-use flags
1230 * along with it.
1231 * Reset the survey data for the new channel, unless we're switching
1232 * back to the operating channel from an off-channel operation.
1233 */
1234 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1235 sc->cur_survey != &sc->survey[pos]) {
1236
1237 if (sc->cur_survey)
1238 sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
1239
1240 sc->cur_survey = &sc->survey[pos];
1241
1242 memset(sc->cur_survey, 0, sizeof(struct survey_info));
1243 sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
1244 } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
1245 memset(&sc->survey[pos], 0, sizeof(struct survey_info));
1246 }
1247
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001248 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Joe Perches38002762010-12-02 19:12:36 -08001249 ath_err(common, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301250 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05301251 return -EINVAL;
1252 }
Felix Fietkau34300982010-10-10 18:21:52 +02001253
1254 /*
1255 * The most recent snapshot of channel->noisefloor for the old
1256 * channel is only available after the hardware reset. Copy it to
1257 * the survey stats now.
1258 */
1259 if (old_pos >= 0)
1260 ath_update_survey_nf(sc, old_pos);
Sujith094d05d2008-12-12 11:57:43 +05301261 }
Sujith86b89ee2008-08-07 10:54:57 +05301262
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001263 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001264 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
Sujith17d79042009-02-09 13:27:03 +05301265 sc->config.txpowlimit = 2 * conf->power_level;
Rajkumar Manoharan5048e8c2011-01-31 23:47:44 +05301266 ath9k_cmn_update_txpow(ah, sc->curtxpow,
1267 sc->config.txpowlimit, &sc->curtxpow);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001268 }
1269
Sujithaa33de02008-12-18 11:40:16 +05301270 mutex_unlock(&sc->mutex);
Felix Fietkauc0c11742011-11-16 13:08:41 +01001271 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301272
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273 return 0;
1274}
1275
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001276#define SUPPORTED_FILTERS \
1277 (FIF_PROMISC_IN_BSS | \
1278 FIF_ALLMULTI | \
1279 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001280 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001281 FIF_OTHER_BSS | \
1282 FIF_BCN_PRBRESP_PROMISC | \
Jouni Malinen9c1d8e42010-10-13 17:29:31 +03001283 FIF_PROBE_REQ | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001284 FIF_FCSFAIL)
1285
Sujith7dcfdcd2008-08-11 14:03:13 +05301286/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001287static void ath9k_configure_filter(struct ieee80211_hw *hw,
1288 unsigned int changed_flags,
1289 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001290 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001291{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001292 struct ath_softc *sc = hw->priv;
Sujith7dcfdcd2008-08-11 14:03:13 +05301293 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294
1295 changed_flags &= SUPPORTED_FILTERS;
1296 *total_flags &= SUPPORTED_FILTERS;
1297
Sujithb77f4832008-12-07 21:44:03 +05301298 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001299 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301300 rfilt = ath_calcrxfilter(sc);
1301 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001302 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301303
Joe Perchesd2182b62011-12-15 14:55:53 -08001304 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
1305 rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001306}
1307
Johannes Berg4ca77862010-02-19 19:06:56 +01001308static int ath9k_sta_add(struct ieee80211_hw *hw,
1309 struct ieee80211_vif *vif,
1310 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001311{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001312 struct ath_softc *sc = hw->priv;
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001313 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1314 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1315 struct ieee80211_key_conf ps_key = { };
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001316
Ben Greear7e1e3862011-11-03 11:33:13 -07001317 ath_node_attach(sc, sta, vif);
Felix Fietkauf59a59f2011-05-10 20:52:22 +02001318
1319 if (vif->type != NL80211_IFTYPE_AP &&
1320 vif->type != NL80211_IFTYPE_AP_VLAN)
1321 return 0;
1322
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001323 an->ps_key = ath_key_config(common, vif, sta, &ps_key);
Johannes Berg4ca77862010-02-19 19:06:56 +01001324
1325 return 0;
1326}
1327
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001328static void ath9k_del_ps_key(struct ath_softc *sc,
1329 struct ieee80211_vif *vif,
1330 struct ieee80211_sta *sta)
1331{
1332 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1333 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1334 struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
1335
1336 if (!an->ps_key)
1337 return;
1338
1339 ath_key_delete(common, &ps_key);
1340}
1341
Johannes Berg4ca77862010-02-19 19:06:56 +01001342static int ath9k_sta_remove(struct ieee80211_hw *hw,
1343 struct ieee80211_vif *vif,
1344 struct ieee80211_sta *sta)
1345{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001346 struct ath_softc *sc = hw->priv;
Johannes Berg4ca77862010-02-19 19:06:56 +01001347
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001348 ath9k_del_ps_key(sc, vif, sta);
Johannes Berg4ca77862010-02-19 19:06:56 +01001349 ath_node_detach(sc, sta);
1350
1351 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352}
1353
Felix Fietkau55195412011-04-17 23:28:09 +02001354static void ath9k_sta_notify(struct ieee80211_hw *hw,
1355 struct ieee80211_vif *vif,
1356 enum sta_notify_cmd cmd,
1357 struct ieee80211_sta *sta)
1358{
1359 struct ath_softc *sc = hw->priv;
1360 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1361
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +05301362 if (!sta->ht_cap.ht_supported)
Mohammed Shafi Shajakhanb25bfda2011-12-26 10:42:15 +05301363 return;
1364
Felix Fietkau55195412011-04-17 23:28:09 +02001365 switch (cmd) {
1366 case STA_NOTIFY_SLEEP:
1367 an->sleeping = true;
Johannes Berg042ec452011-09-29 16:04:26 +02001368 ath_tx_aggr_sleep(sta, sc, an);
Felix Fietkau55195412011-04-17 23:28:09 +02001369 break;
1370 case STA_NOTIFY_AWAKE:
1371 an->sleeping = false;
1372 ath_tx_aggr_wakeup(sc, an);
1373 break;
1374 }
1375}
1376
Eliad Peller8a3a3c82011-10-02 10:15:52 +02001377static int ath9k_conf_tx(struct ieee80211_hw *hw,
1378 struct ieee80211_vif *vif, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001379 const struct ieee80211_tx_queue_params *params)
1380{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001381 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001382 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau066dae92010-11-07 14:59:39 +01001383 struct ath_txq *txq;
Sujithea9880f2008-08-07 10:53:10 +05301384 struct ath9k_tx_queue_info qi;
Felix Fietkau066dae92010-11-07 14:59:39 +01001385 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001386
1387 if (queue >= WME_NUM_AC)
1388 return 0;
1389
Felix Fietkau066dae92010-11-07 14:59:39 +01001390 txq = sc->tx.txq_map[queue];
1391
Felix Fietkau96f372c2011-04-07 19:07:17 +02001392 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301393 mutex_lock(&sc->mutex);
1394
Sujith1ffb0612009-03-30 15:28:46 +05301395 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1396
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001397 qi.tqi_aifs = params->aifs;
1398 qi.tqi_cwmin = params->cw_min;
1399 qi.tqi_cwmax = params->cw_max;
1400 qi.tqi_burstTime = params->txop;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001401
Joe Perchesd2182b62011-12-15 14:55:53 -08001402 ath_dbg(common, CONFIG,
Joe Perches226afe62010-12-02 19:12:37 -08001403 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1404 queue, txq->axq_qnum, params->aifs, params->cw_min,
1405 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001406
Felix Fietkau066dae92010-11-07 14:59:39 +01001407 ret = ath_txq_update(sc, txq->axq_qnum, &qi);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001408 if (ret)
Joe Perches38002762010-12-02 19:12:36 -08001409 ath_err(common, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001410
Vivek Natarajan94db2932009-11-25 12:01:54 +05301411 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
Felix Fietkau066dae92010-11-07 14:59:39 +01001412 if (queue == WME_AC_BE && !ret)
Vivek Natarajan94db2932009-11-25 12:01:54 +05301413 ath_beaconq_config(sc);
1414
Sujith141b38b2009-02-04 08:10:07 +05301415 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001416 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301417
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001418 return ret;
1419}
1420
1421static int ath9k_set_key(struct ieee80211_hw *hw,
1422 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001423 struct ieee80211_vif *vif,
1424 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001425 struct ieee80211_key_conf *key)
1426{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001427 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001428 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001429 int ret = 0;
1430
John W. Linville3e6109c2011-01-05 09:39:17 -05001431 if (ath9k_modparam_nohwcrypt)
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001432 return -ENOSPC;
1433
Chun-Yeow Yeoh5bd5e9a2011-12-07 12:45:46 -08001434 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1435 vif->type == NL80211_IFTYPE_MESH_POINT) &&
Jouni Malinencfdc9a82011-03-23 14:52:19 +02001436 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1437 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1438 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1439 /*
1440 * For now, disable hw crypto for the RSN IBSS group keys. This
1441 * could be optimized in the future to use a modified key cache
1442 * design to support per-STA RX GTK, but until that gets
1443 * implemented, use of software crypto for group addressed
1444 * frames is a acceptable to allow RSN IBSS to be used.
1445 */
1446 return -EOPNOTSUPP;
1447 }
1448
Sujith141b38b2009-02-04 08:10:07 +05301449 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301450 ath9k_ps_wakeup(sc);
Joe Perchesd2182b62011-12-15 14:55:53 -08001451 ath_dbg(common, CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001452
1453 switch (cmd) {
1454 case SET_KEY:
Felix Fietkau93ae2dd2011-04-17 23:28:10 +02001455 if (sta)
1456 ath9k_del_ps_key(sc, vif, sta);
1457
Bruno Randolf040e5392010-09-08 16:05:04 +09001458 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001459 if (ret >= 0) {
1460 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001461 /* push IV and Michael MIC generation to stack */
1462 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Johannes Berg97359d12010-08-10 09:46:38 +02001463 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301464 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg97359d12010-08-10 09:46:38 +02001465 if (sc->sc_ah->sw_mgmt_crypto &&
1466 key->cipher == WLAN_CIPHER_SUITE_CCMP)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001467 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001468 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469 }
1470 break;
1471 case DISABLE_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001472 ath_key_delete(common, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001473 break;
1474 default:
1475 ret = -EINVAL;
1476 }
1477
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301478 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301479 mutex_unlock(&sc->mutex);
1480
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001481 return ret;
1482}
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301483static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1484{
1485 struct ath_softc *sc = data;
1486 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1487 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1488 struct ath_vif *avp = (void *)vif->drv_priv;
Sujith Manoharan07c15a32012-06-04 20:24:07 +05301489 unsigned long flags;
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301490 /*
1491 * Skip iteration if primary station vif's bss info
1492 * was not changed
1493 */
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301494 if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301495 return;
1496
1497 if (bss_conf->assoc) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301498 set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301499 avp->primary_sta_vif = true;
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301500 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1501 common->curaid = bss_conf->aid;
1502 ath9k_hw_write_associd(sc->sc_ah);
Joe Perchesd2182b62011-12-15 14:55:53 -08001503 ath_dbg(common, CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
1504 bss_conf->aid, common->curbssid);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301505 ath_beacon_config(sc, vif);
1506 /*
1507 * Request a re-configuration of Beacon related timers
1508 * on the receipt of the first Beacon frame (i.e.,
1509 * after time sync with the AP).
1510 */
Sujith Manoharan07c15a32012-06-04 20:24:07 +05301511 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301512 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
Sujith Manoharan07c15a32012-06-04 20:24:07 +05301513 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1514
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301515 /* Reset rssi stats */
1516 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
1517 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +05301518
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301519 ath_start_rx_poll(sc, 3);
1520
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +05301521 if (!common->disable_ani) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301522 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +05301523 ath_start_ani(common);
1524 }
1525
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301526 }
1527}
1528
1529static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
1530{
1531 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1532 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1533 struct ath_vif *avp = (void *)vif->drv_priv;
1534
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301535 if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
1536 return;
1537
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301538 /* Reconfigure bss info */
1539 if (avp->primary_sta_vif && !bss_conf->assoc) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001540 ath_dbg(common, CONFIG, "Bss Info DISASSOC %d, bssid %pM\n",
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +05301541 common->curaid, common->curbssid);
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301542 clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
1543 clear_bit(SC_OP_BEACONS, &sc->sc_flags);
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301544 avp->primary_sta_vif = false;
1545 memset(common->curbssid, 0, ETH_ALEN);
1546 common->curaid = 0;
1547 }
1548
1549 ieee80211_iterate_active_interfaces_atomic(
1550 sc->hw, ath9k_bss_iter, sc);
1551
1552 /*
1553 * None of station vifs are associated.
1554 * Clear bssid & aid
1555 */
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301556 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301557 ath9k_hw_write_associd(sc->sc_ah);
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301558 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +05301559 del_timer_sync(&common->ani.timer);
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301560 del_timer_sync(&sc->rx_poll_timer);
Rajkumar Manoharand2c71c22011-09-15 19:02:54 +05301561 memset(&sc->caldata, 0, sizeof(sc->caldata));
Rajkumar Manoharan99e4d432011-04-04 22:56:19 +05301562 }
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301563}
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001564
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001565static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1566 struct ieee80211_vif *vif,
1567 struct ieee80211_bss_conf *bss_conf,
1568 u32 changed)
1569{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001570 struct ath_softc *sc = hw->priv;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001571 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001572 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001573 struct ath_vif *avp = (void *)vif->drv_priv;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001574 int slottime;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001575
Felix Fietkau96f372c2011-04-07 19:07:17 +02001576 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301577 mutex_lock(&sc->mutex);
1578
Rajkumar Manoharan9f619032012-03-10 05:06:49 +05301579 if (changed & BSS_CHANGED_ASSOC) {
Rajkumar Manoharan4f5ef75b2011-04-04 22:56:18 +05301580 ath9k_config_bss(sc, vif);
Sujithc6089cc2009-11-16 11:40:48 +05301581
Joe Perchesd2182b62011-12-15 14:55:53 -08001582 ath_dbg(common, CONFIG, "BSSID: %pM aid: 0x%x\n",
Joe Perches226afe62010-12-02 19:12:37 -08001583 common->curbssid, common->curaid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001584 }
1585
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301586 if (changed & BSS_CHANGED_IBSS) {
1587 /* There can be only one vif available */
1588 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1589 common->curaid = bss_conf->aid;
1590 ath9k_hw_write_associd(sc->sc_ah);
1591
1592 if (bss_conf->ibss_joined) {
1593 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +05301594
1595 if (!common->disable_ani) {
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301596 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +05301597 ath_start_ani(common);
1598 }
1599
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301600 } else {
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301601 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301602 del_timer_sync(&common->ani.timer);
Rajkumar Manoharan01e18912012-03-15 05:34:27 +05301603 del_timer_sync(&sc->rx_poll_timer);
Rajkumar Manoharan2e5ef452011-05-20 17:52:12 +05301604 }
1605 }
1606
Rajkumar Manoharaned2578c2012-04-19 19:13:51 +05301607 /*
1608 * In case of AP mode, the HW TSF has to be reset
1609 * when the beacon interval changes.
1610 */
1611 if ((changed & BSS_CHANGED_BEACON_INT) &&
1612 (vif->type == NL80211_IFTYPE_AP))
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301613 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
Rajkumar Manoharaned2578c2012-04-19 19:13:51 +05301614
1615 /* Configure beaconing (AP, IBSS, MESH) */
1616 if (ath9k_uses_beacons(vif->type) &&
1617 ((changed & BSS_CHANGED_BEACON) ||
1618 (changed & BSS_CHANGED_BEACON_ENABLED) ||
1619 (changed & BSS_CHANGED_BEACON_INT))) {
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +05301620 ath9k_set_beaconing_status(sc, false);
Rajkumar Manoharaned2578c2012-04-19 19:13:51 +05301621 if (bss_conf->enable_beacon)
1622 ath_beacon_alloc(sc, vif);
1623 else
1624 avp->is_bslot_active = false;
1625 ath_beacon_config(sc, vif);
Rajkumar Manoharan014cf3b2011-02-09 17:46:39 +05301626 ath9k_set_beaconing_status(sc, true);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001627 }
1628
Felix Fietkau0005baf2010-01-15 02:33:40 +01001629 if (changed & BSS_CHANGED_ERP_SLOT) {
1630 if (bss_conf->use_short_slot)
1631 slottime = 9;
1632 else
1633 slottime = 20;
1634 if (vif->type == NL80211_IFTYPE_AP) {
1635 /*
1636 * Defer update, so that connected stations can adjust
1637 * their settings at the same time.
1638 * See beacon.c for more details
1639 */
1640 sc->beacon.slottime = slottime;
1641 sc->beacon.updateslot = UPDATE;
1642 } else {
1643 ah->slottime = slottime;
1644 ath9k_hw_init_global_settings(ah);
1645 }
1646 }
1647
Sujith141b38b2009-02-04 08:10:07 +05301648 mutex_unlock(&sc->mutex);
Felix Fietkau96f372c2011-04-07 19:07:17 +02001649 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001650}
1651
Eliad Peller37a41b42011-09-21 14:06:11 +03001652static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001653{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001654 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001655 u64 tsf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001656
Sujith141b38b2009-02-04 08:10:07 +05301657 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301658 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301659 tsf = ath9k_hw_gettsf64(sc->sc_ah);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301660 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301661 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001662
1663 return tsf;
1664}
1665
Eliad Peller37a41b42011-09-21 14:06:11 +03001666static void ath9k_set_tsf(struct ieee80211_hw *hw,
1667 struct ieee80211_vif *vif,
1668 u64 tsf)
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001669{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001670 struct ath_softc *sc = hw->priv;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001671
Sujith141b38b2009-02-04 08:10:07 +05301672 mutex_lock(&sc->mutex);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301673 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301674 ath9k_hw_settsf64(sc->sc_ah, tsf);
Sujith Manoharan9abbfb22010-12-10 11:27:06 +05301675 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301676 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001677}
1678
Eliad Peller37a41b42011-09-21 14:06:11 +03001679static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001680{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001681 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682
Sujith141b38b2009-02-04 08:10:07 +05301683 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001684
1685 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301686 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001687 ath9k_ps_restore(sc);
1688
Sujith141b38b2009-02-04 08:10:07 +05301689 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001690}
1691
1692static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01001693 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05301694 enum ieee80211_ampdu_mlme_action action,
1695 struct ieee80211_sta *sta,
Johannes Berg0b01f032011-01-18 13:51:05 +01001696 u16 tid, u16 *ssn, u8 buf_size)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001697{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001698 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699 int ret = 0;
1700
Johannes Berg85ad1812010-06-10 10:21:49 +02001701 local_bh_disable();
1702
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001703 switch (action) {
1704 case IEEE80211_AMPDU_RX_START:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001705 break;
1706 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001707 break;
1708 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001709 ath9k_ps_wakeup(sc);
Felix Fietkau231c3a12010-09-20 19:35:28 +02001710 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1711 if (!ret)
1712 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001713 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714 break;
1715 case IEEE80211_AMPDU_TX_STOP:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001716 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301717 ath_tx_aggr_stop(sc, sta, tid);
Johannes Bergc951ad32009-11-16 12:00:38 +01001718 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001719 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001720 break;
Johannes Bergb1720232009-03-23 17:28:39 +01001721 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001722 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05301723 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001724 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05301725 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001726 default:
Joe Perches38002762010-12-02 19:12:36 -08001727 ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001728 }
1729
Johannes Berg85ad1812010-06-10 10:21:49 +02001730 local_bh_enable();
1731
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001732 return ret;
1733}
1734
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001735static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
1736 struct survey_info *survey)
1737{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001738 struct ath_softc *sc = hw->priv;
Felix Fietkau34300982010-10-10 18:21:52 +02001739 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39162db2010-09-29 19:12:06 +02001740 struct ieee80211_supported_band *sband;
Felix Fietkau34300982010-10-10 18:21:52 +02001741 struct ieee80211_channel *chan;
1742 unsigned long flags;
1743 int pos;
1744
1745 spin_lock_irqsave(&common->cc_lock, flags);
1746 if (idx == 0)
1747 ath_update_survey_stats(sc);
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001748
Felix Fietkau39162db2010-09-29 19:12:06 +02001749 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
1750 if (sband && idx >= sband->n_channels) {
1751 idx -= sband->n_channels;
1752 sband = NULL;
1753 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001754
Felix Fietkau39162db2010-09-29 19:12:06 +02001755 if (!sband)
1756 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
1757
Felix Fietkau34300982010-10-10 18:21:52 +02001758 if (!sband || idx >= sband->n_channels) {
1759 spin_unlock_irqrestore(&common->cc_lock, flags);
1760 return -ENOENT;
Felix Fietkau4f1a5a42010-09-29 17:15:28 +02001761 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001762
Felix Fietkau34300982010-10-10 18:21:52 +02001763 chan = &sband->channels[idx];
1764 pos = chan->hw_value;
1765 memcpy(survey, &sc->survey[pos], sizeof(*survey));
1766 survey->channel = chan;
1767 spin_unlock_irqrestore(&common->cc_lock, flags);
1768
Benoit Papillault62dad5b2010-04-28 00:08:24 +02001769 return 0;
1770}
1771
Felix Fietkaue239d852010-01-15 02:34:58 +01001772static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
1773{
Felix Fietkau9ac586152011-01-24 19:23:18 +01001774 struct ath_softc *sc = hw->priv;
Felix Fietkaue239d852010-01-15 02:34:58 +01001775 struct ath_hw *ah = sc->sc_ah;
1776
1777 mutex_lock(&sc->mutex);
1778 ah->coverage_class = coverage_class;
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301779
1780 ath9k_ps_wakeup(sc);
Felix Fietkaue239d852010-01-15 02:34:58 +01001781 ath9k_hw_init_global_settings(ah);
Mohammed Shafi Shajakhan8b2a38272011-08-24 21:38:07 +05301782 ath9k_ps_restore(sc);
1783
Felix Fietkaue239d852010-01-15 02:34:58 +01001784 mutex_unlock(&sc->mutex);
1785}
1786
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001787static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
1788{
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001789 struct ath_softc *sc = hw->priv;
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301790 struct ath_hw *ah = sc->sc_ah;
1791 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau86271e42011-03-11 21:38:19 +01001792 int timeout = 200; /* ms */
1793 int i, j;
Rajkumar Manoharan2f6fc352011-04-28 15:31:57 +05301794 bool drain_txq;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001795
1796 mutex_lock(&sc->mutex);
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001797 cancel_delayed_work_sync(&sc->tx_complete_work);
1798
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301799 if (ah->ah_flags & AH_UNPLUGGED) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001800 ath_dbg(common, ANY, "Device has been unplugged!\n");
Mohammed Shafi Shajakhan6a6b3f32011-09-09 10:41:08 +05301801 mutex_unlock(&sc->mutex);
1802 return;
1803 }
1804
Sujith Manoharan781b14a2012-06-04 20:23:55 +05301805 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001806 ath_dbg(common, ANY, "Device not present\n");
Mohammed Shafi Shajakhan99aa55b2011-05-06 20:43:11 +05301807 mutex_unlock(&sc->mutex);
1808 return;
1809 }
1810
Felix Fietkau86271e42011-03-11 21:38:19 +01001811 for (j = 0; j < timeout; j++) {
Mohammed Shafi Shajakhan108697c2011-05-13 20:59:42 +05301812 bool npend = false;
Felix Fietkau86271e42011-03-11 21:38:19 +01001813
1814 if (j)
1815 usleep_range(1000, 2000);
1816
1817 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1818 if (!ATH_TXQ_SETUP(sc, i))
1819 continue;
1820
Mohammed Shafi Shajakhan108697c2011-05-13 20:59:42 +05301821 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
1822
1823 if (npend)
1824 break;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001825 }
1826
Felix Fietkau86271e42011-03-11 21:38:19 +01001827 if (!npend)
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001828 break;
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001829 }
1830
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001831 if (drop) {
1832 ath9k_ps_wakeup(sc);
1833 spin_lock_bh(&sc->sc_pcu_lock);
1834 drain_txq = ath_drain_all_txq(sc, false);
1835 spin_unlock_bh(&sc->sc_pcu_lock);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001836
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001837 if (!drain_txq)
1838 ath_reset(sc, false);
Felix Fietkau9adcf442011-09-03 01:40:26 +02001839
Felix Fietkau9df0d6a2011-11-16 13:08:42 +01001840 ath9k_ps_restore(sc);
1841 ieee80211_wake_queues(hw);
1842 }
Senthil Balasubramaniand78f4b32011-03-23 23:07:22 +05301843
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08001844 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
1845 mutex_unlock(&sc->mutex);
1846}
1847
Vivek Natarajan15b91e82011-04-06 11:41:11 +05301848static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
1849{
1850 struct ath_softc *sc = hw->priv;
1851 int i;
1852
1853 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1854 if (!ATH_TXQ_SETUP(sc, i))
1855 continue;
1856
1857 if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
1858 return true;
1859 }
1860 return false;
1861}
1862
Mohammed Shafi Shajakhan5595f112011-05-19 18:08:57 +05301863static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
Felix Fietkauba4903f2011-05-17 21:09:54 +02001864{
1865 struct ath_softc *sc = hw->priv;
1866 struct ath_hw *ah = sc->sc_ah;
1867 struct ieee80211_vif *vif;
1868 struct ath_vif *avp;
1869 struct ath_buf *bf;
1870 struct ath_tx_status ts;
Felix Fietkau4286df62012-02-27 19:58:40 +01001871 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
Felix Fietkauba4903f2011-05-17 21:09:54 +02001872 int status;
1873
1874 vif = sc->beacon.bslot[0];
1875 if (!vif)
1876 return 0;
1877
1878 avp = (void *)vif->drv_priv;
1879 if (!avp->is_bslot_active)
1880 return 0;
1881
Felix Fietkau4286df62012-02-27 19:58:40 +01001882 if (!sc->beacon.tx_processed && !edma) {
Felix Fietkauba4903f2011-05-17 21:09:54 +02001883 tasklet_disable(&sc->bcon_tasklet);
1884
1885 bf = avp->av_bcbuf;
1886 if (!bf || !bf->bf_mpdu)
1887 goto skip;
1888
1889 status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
1890 if (status == -EINPROGRESS)
1891 goto skip;
1892
1893 sc->beacon.tx_processed = true;
1894 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
1895
1896skip:
1897 tasklet_enable(&sc->bcon_tasklet);
1898 }
1899
1900 return sc->beacon.tx_last;
1901}
1902
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05301903static int ath9k_get_stats(struct ieee80211_hw *hw,
1904 struct ieee80211_low_level_stats *stats)
1905{
1906 struct ath_softc *sc = hw->priv;
1907 struct ath_hw *ah = sc->sc_ah;
1908 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
1909
1910 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
1911 stats->dot11RTSFailureCount = mib_stats->rts_bad;
1912 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
1913 stats->dot11RTSSuccessCount = mib_stats->rts_good;
1914 return 0;
1915}
1916
Felix Fietkau43c35282011-09-03 01:40:27 +02001917static u32 fill_chainmask(u32 cap, u32 new)
1918{
1919 u32 filled = 0;
1920 int i;
1921
1922 for (i = 0; cap && new; i++, cap >>= 1) {
1923 if (!(cap & BIT(0)))
1924 continue;
1925
1926 if (new & BIT(0))
1927 filled |= BIT(i);
1928
1929 new >>= 1;
1930 }
1931
1932 return filled;
1933}
1934
1935static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
1936{
1937 struct ath_softc *sc = hw->priv;
1938 struct ath_hw *ah = sc->sc_ah;
1939
1940 if (!rx_ant || !tx_ant)
1941 return -EINVAL;
1942
1943 sc->ant_rx = rx_ant;
1944 sc->ant_tx = tx_ant;
1945
1946 if (ah->caps.rx_chainmask == 1)
1947 return 0;
1948
1949 /* AR9100 runs into calibration issues if not all rx chains are enabled */
1950 if (AR_SREV_9100(ah))
1951 ah->rxchainmask = 0x7;
1952 else
1953 ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
1954
1955 ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
1956 ath9k_reload_chainmask_settings(sc);
1957
1958 return 0;
1959}
1960
1961static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
1962{
1963 struct ath_softc *sc = hw->priv;
1964
1965 *tx_ant = sc->ant_tx;
1966 *rx_ant = sc->ant_rx;
1967 return 0;
1968}
1969
Ben Greearb90bd9d2012-05-15 15:33:25 -07001970#ifdef CONFIG_ATH9K_DEBUGFS
1971
1972/* Ethtool support for get-stats */
1973
1974#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1975static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1976 "tx_pkts_nic",
1977 "tx_bytes_nic",
1978 "rx_pkts_nic",
1979 "rx_bytes_nic",
1980 AMKSTR(d_tx_pkts),
1981 AMKSTR(d_tx_bytes),
1982 AMKSTR(d_tx_mpdus_queued),
1983 AMKSTR(d_tx_mpdus_completed),
1984 AMKSTR(d_tx_mpdu_xretries),
1985 AMKSTR(d_tx_aggregates),
1986 AMKSTR(d_tx_ampdus_queued_hw),
1987 AMKSTR(d_tx_ampdus_queued_sw),
1988 AMKSTR(d_tx_ampdus_completed),
1989 AMKSTR(d_tx_ampdu_retries),
1990 AMKSTR(d_tx_ampdu_xretries),
1991 AMKSTR(d_tx_fifo_underrun),
1992 AMKSTR(d_tx_op_exceeded),
1993 AMKSTR(d_tx_timer_expiry),
1994 AMKSTR(d_tx_desc_cfg_err),
1995 AMKSTR(d_tx_data_underrun),
1996 AMKSTR(d_tx_delim_underrun),
1997
1998 "d_rx_decrypt_crc_err",
1999 "d_rx_phy_err",
2000 "d_rx_mic_err",
2001 "d_rx_pre_delim_crc_err",
2002 "d_rx_post_delim_crc_err",
2003 "d_rx_decrypt_busy_err",
2004
2005 "d_rx_phyerr_radar",
2006 "d_rx_phyerr_ofdm_timing",
2007 "d_rx_phyerr_cck_timing",
2008
2009};
2010#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
2011
2012static void ath9k_get_et_strings(struct ieee80211_hw *hw,
2013 struct ieee80211_vif *vif,
2014 u32 sset, u8 *data)
2015{
2016 if (sset == ETH_SS_STATS)
2017 memcpy(data, *ath9k_gstrings_stats,
2018 sizeof(ath9k_gstrings_stats));
2019}
2020
2021static int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
2022 struct ieee80211_vif *vif, int sset)
2023{
2024 if (sset == ETH_SS_STATS)
2025 return ATH9K_SSTATS_LEN;
2026 return 0;
2027}
2028
2029#define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
2030#define AWDATA(elem) \
2031 do { \
2032 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem; \
2033 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem; \
2034 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem; \
2035 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem; \
2036 } while (0)
2037
2038#define AWDATA_RX(elem) \
2039 do { \
2040 data[i++] = sc->debug.stats.rxstats.elem; \
2041 } while (0)
2042
2043static void ath9k_get_et_stats(struct ieee80211_hw *hw,
2044 struct ieee80211_vif *vif,
2045 struct ethtool_stats *stats, u64 *data)
2046{
2047 struct ath_softc *sc = hw->priv;
2048 int i = 0;
2049
2050 data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_pkts_all +
2051 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_pkts_all +
2052 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_pkts_all +
2053 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_pkts_all);
2054 data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_bytes_all +
2055 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_bytes_all +
2056 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_bytes_all +
2057 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_bytes_all);
2058 AWDATA_RX(rx_pkts_all);
2059 AWDATA_RX(rx_bytes_all);
2060
2061 AWDATA(tx_pkts_all);
2062 AWDATA(tx_bytes_all);
2063 AWDATA(queued);
2064 AWDATA(completed);
2065 AWDATA(xretries);
2066 AWDATA(a_aggr);
2067 AWDATA(a_queued_hw);
2068 AWDATA(a_queued_sw);
2069 AWDATA(a_completed);
2070 AWDATA(a_retries);
2071 AWDATA(a_xretries);
2072 AWDATA(fifo_underrun);
2073 AWDATA(xtxop);
2074 AWDATA(timer_exp);
2075 AWDATA(desc_cfg_err);
2076 AWDATA(data_underrun);
2077 AWDATA(delim_underrun);
2078
2079 AWDATA_RX(decrypt_crc_err);
2080 AWDATA_RX(phy_err);
2081 AWDATA_RX(mic_err);
2082 AWDATA_RX(pre_delim_crc_err);
2083 AWDATA_RX(post_delim_crc_err);
2084 AWDATA_RX(decrypt_busy_err);
2085
2086 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
2087 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
2088 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
2089
2090 WARN_ON(i != ATH9K_SSTATS_LEN);
2091}
2092
2093/* End of ethtool get-stats functions */
2094
2095#endif
2096
2097
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002098struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002099 .tx = ath9k_tx,
2100 .start = ath9k_start,
2101 .stop = ath9k_stop,
2102 .add_interface = ath9k_add_interface,
Rajkumar Manoharan6b3b9912010-12-08 19:38:55 +05302103 .change_interface = ath9k_change_interface,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002104 .remove_interface = ath9k_remove_interface,
2105 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002106 .configure_filter = ath9k_configure_filter,
Johannes Berg4ca77862010-02-19 19:06:56 +01002107 .sta_add = ath9k_sta_add,
2108 .sta_remove = ath9k_sta_remove,
Felix Fietkau55195412011-04-17 23:28:09 +02002109 .sta_notify = ath9k_sta_notify,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002110 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002111 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002112 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002113 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002114 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002115 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002116 .ampdu_action = ath9k_ampdu_action,
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002117 .get_survey = ath9k_get_survey,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302118 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002119 .set_coverage_class = ath9k_set_coverage_class,
Vasanthakumar Thiagarajan69081622011-02-19 01:13:42 -08002120 .flush = ath9k_flush,
Vivek Natarajan15b91e82011-04-06 11:41:11 +05302121 .tx_frames_pending = ath9k_tx_frames_pending,
Mohammed Shafi Shajakhan52c94f42011-08-20 17:21:42 +05302122 .tx_last_beacon = ath9k_tx_last_beacon,
2123 .get_stats = ath9k_get_stats,
Felix Fietkau43c35282011-09-03 01:40:27 +02002124 .set_antenna = ath9k_set_antenna,
2125 .get_antenna = ath9k_get_antenna,
Ben Greearb90bd9d2012-05-15 15:33:25 -07002126
2127#ifdef CONFIG_ATH9K_DEBUGFS
2128 .get_et_sset_count = ath9k_get_et_sset_count,
2129 .get_et_stats = ath9k_get_et_stats,
2130 .get_et_strings = ath9k_get_et_strings,
2131#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002132};