blob: 928ef68ab40c948d4d4a037d7a555c54b11446bb [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 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>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070019#include "btcoex.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Sujithff37e332008-11-24 12:07:55 +053021static void ath_update_txpow(struct ath_softc *sc)
22{
Sujithcbe61d82009-02-09 13:27:12 +053023 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +053024
Sujith17d79042009-02-09 13:27:03 +053025 if (sc->curtxpow != sc->config.txpowlimit) {
26 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +053027 /* read back in case value is clamped */
Felix Fietkau9cc32712010-06-12 17:22:29 +020028 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
Sujithff37e332008-11-24 12:07:55 +053029 }
30}
31
32static u8 parse_mpdudensity(u8 mpdudensity)
33{
34 /*
35 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
36 * 0 for no restriction
37 * 1 for 1/4 us
38 * 2 for 1/2 us
39 * 3 for 1 us
40 * 4 for 2 us
41 * 5 for 4 us
42 * 6 for 8 us
43 * 7 for 16 us
44 */
45 switch (mpdudensity) {
46 case 0:
47 return 0;
48 case 1:
49 case 2:
50 case 3:
51 /* Our lower layer calculations limit our precision to
52 1 microsecond */
53 return 1;
54 case 4:
55 return 2;
56 case 5:
57 return 4;
58 case 6:
59 return 8;
60 case 7:
61 return 16;
62 default:
63 return 0;
64 }
65}
66
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +053067static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
68 struct ieee80211_hw *hw)
69{
70 struct ieee80211_channel *curchan = hw->conf.channel;
71 struct ath9k_channel *channel;
72 u8 chan_idx;
73
74 chan_idx = curchan->hw_value;
75 channel = &sc->sc_ah->channels[chan_idx];
76 ath9k_update_ichannel(sc, hw, channel);
77 return channel;
78}
79
Sujith55624202010-01-08 10:36:02 +053080bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070081{
82 unsigned long flags;
83 bool ret;
84
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070085 spin_lock_irqsave(&sc->sc_pm_lock, flags);
86 ret = ath9k_hw_setpower(sc->sc_ah, mode);
87 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070088
89 return ret;
90}
91
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -070092void ath9k_ps_wakeup(struct ath_softc *sc)
93{
Felix Fietkau898c9142010-10-12 14:02:53 +020094 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -070095 unsigned long flags;
Felix Fietkaufbb078f2010-11-03 01:36:51 +010096 enum ath9k_power_mode power_mode;
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -070097
98 spin_lock_irqsave(&sc->sc_pm_lock, flags);
99 if (++sc->ps_usecount != 1)
100 goto unlock;
101
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100102 power_mode = sc->sc_ah->power_mode;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700103 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700104
Felix Fietkau898c9142010-10-12 14:02:53 +0200105 /*
106 * While the hardware is asleep, the cycle counters contain no
107 * useful data. Better clear them now so that they don't mess up
108 * survey data results.
109 */
Felix Fietkaufbb078f2010-11-03 01:36:51 +0100110 if (power_mode != ATH9K_PM_AWAKE) {
111 spin_lock(&common->cc_lock);
112 ath_hw_cycle_counters_update(common);
113 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
114 spin_unlock(&common->cc_lock);
115 }
Felix Fietkau898c9142010-10-12 14:02:53 +0200116
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700117 unlock:
118 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
119}
120
121void ath9k_ps_restore(struct ath_softc *sc)
122{
Felix Fietkau898c9142010-10-12 14:02:53 +0200123 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700124 unsigned long flags;
125
126 spin_lock_irqsave(&sc->sc_pm_lock, flags);
127 if (--sc->ps_usecount != 0)
128 goto unlock;
129
Felix Fietkau898c9142010-10-12 14:02:53 +0200130 spin_lock(&common->cc_lock);
131 ath_hw_cycle_counters_update(common);
132 spin_unlock(&common->cc_lock);
133
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +0530134 if (sc->ps_idle)
135 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
136 else if (sc->ps_enabled &&
137 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
Sujith1b04b932010-01-08 10:36:05 +0530138 PS_WAIT_FOR_CAB |
139 PS_WAIT_FOR_PSPOLL_DATA |
140 PS_WAIT_FOR_TX_ACK)))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700141 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700142
143 unlock:
144 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
145}
146
Felix Fietkau5ee08652010-07-31 00:11:59 +0200147static void ath_start_ani(struct ath_common *common)
148{
149 struct ath_hw *ah = common->ah;
150 unsigned long timestamp = jiffies_to_msecs(jiffies);
151 struct ath_softc *sc = (struct ath_softc *) common->priv;
152
153 if (!(sc->sc_flags & SC_OP_ANI_RUN))
154 return;
155
156 if (sc->sc_flags & SC_OP_OFFCHANNEL)
157 return;
158
159 common->ani.longcal_timer = timestamp;
160 common->ani.shortcal_timer = timestamp;
161 common->ani.checkani_timer = timestamp;
162
163 mod_timer(&common->ani.timer,
164 jiffies +
165 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
166}
167
Felix Fietkau34300982010-10-10 18:21:52 +0200168static void ath_update_survey_nf(struct ath_softc *sc, int channel)
169{
170 struct ath_hw *ah = sc->sc_ah;
171 struct ath9k_channel *chan = &ah->channels[channel];
172 struct survey_info *survey = &sc->survey[channel];
173
174 if (chan->noisefloor) {
175 survey->filled |= SURVEY_INFO_NOISE_DBM;
176 survey->noise = chan->noisefloor;
177 }
178}
179
180static void ath_update_survey_stats(struct ath_softc *sc)
181{
182 struct ath_hw *ah = sc->sc_ah;
183 struct ath_common *common = ath9k_hw_common(ah);
184 int pos = ah->curchan - &ah->channels[0];
185 struct survey_info *survey = &sc->survey[pos];
186 struct ath_cycle_counters *cc = &common->cc_survey;
187 unsigned int div = common->clockrate * 1000;
188
Felix Fietkau08457352010-10-20 15:59:28 +0200189 if (!ah->curchan)
190 return;
191
Felix Fietkau898c9142010-10-12 14:02:53 +0200192 if (ah->power_mode == ATH9K_PM_AWAKE)
193 ath_hw_cycle_counters_update(common);
Felix Fietkau34300982010-10-10 18:21:52 +0200194
195 if (cc->cycles > 0) {
196 survey->filled |= SURVEY_INFO_CHANNEL_TIME |
197 SURVEY_INFO_CHANNEL_TIME_BUSY |
198 SURVEY_INFO_CHANNEL_TIME_RX |
199 SURVEY_INFO_CHANNEL_TIME_TX;
200 survey->channel_time += cc->cycles / div;
201 survey->channel_time_busy += cc->rx_busy / div;
202 survey->channel_time_rx += cc->rx_frame / div;
203 survey->channel_time_tx += cc->tx_frame / div;
204 }
205 memset(cc, 0, sizeof(*cc));
206
207 ath_update_survey_nf(sc, pos);
208}
209
Sujithff37e332008-11-24 12:07:55 +0530210/*
211 * Set/change channels. If the channel is really being changed, it's done
212 * by reseting the chip. To accomplish this we must first cleanup any pending
213 * DMA, then restart stuff.
214*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200215int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
216 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530217{
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200218 struct ath_wiphy *aphy = hw->priv;
Sujithcbe61d82009-02-09 13:27:12 +0530219 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700220 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700221 struct ieee80211_conf *conf = &common->hw->conf;
Sujithff37e332008-11-24 12:07:55 +0530222 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800223 struct ieee80211_channel *channel = hw->conf.channel;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200224 struct ath9k_hw_cal_data *caldata = NULL;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800225 int r;
Sujithff37e332008-11-24 12:07:55 +0530226
227 if (sc->sc_flags & SC_OP_INVALID)
228 return -EIO;
229
Felix Fietkau5ee08652010-07-31 00:11:59 +0200230 del_timer_sync(&common->ani.timer);
231 cancel_work_sync(&sc->paprd_work);
232 cancel_work_sync(&sc->hw_check_work);
233 cancel_delayed_work_sync(&sc->tx_complete_work);
234
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530235 ath9k_ps_wakeup(sc);
236
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800237 /*
238 * This is only performed if the channel settings have
239 * actually changed.
240 *
241 * To switch channels clear any pending DMA operations;
242 * wait long enough for the RX fifo to drain, reset the
243 * hardware at the new frequency, and then re-enable
244 * the relevant bits of the h/w.
245 */
246 ath9k_hw_set_interrupts(ah, 0);
Felix Fietkau080e1a22010-12-05 20:17:53 +0100247 stopped = ath_drain_all_txq(sc, false);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700248
249 spin_lock_bh(&sc->rx.pcu_lock);
250
Felix Fietkau080e1a22010-12-05 20:17:53 +0100251 if (!ath_stoprecv(sc))
252 stopped = false;
Sujithff37e332008-11-24 12:07:55 +0530253
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800254 /* XXX: do not flush receive queue here. We don't want
255 * to flush data frames already in queue because of
256 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530257
Felix Fietkau5ee08652010-07-31 00:11:59 +0200258 if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800259 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530260
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200261 if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
262 caldata = &aphy->caldata;
263
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700264 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguez1e51b2f2010-07-29 22:56:22 -0400265 "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700266 sc->sc_ah->curchan->channel,
Luis R. Rodriguez1e51b2f2010-07-29 22:56:22 -0400267 channel->center_freq, conf_is_ht40(conf),
268 fastcc);
Sujith99405f92008-11-24 12:08:35 +0530269
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800270 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800271
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200272 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800273 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700274 ath_print(common, ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500275 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700276 "reset status %d\n",
277 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530278 spin_unlock_bh(&sc->sc_resetlock);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700279 spin_unlock_bh(&sc->rx.pcu_lock);
Gabor Juhos39892792009-06-15 17:49:09 +0200280 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530281 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800282 spin_unlock_bh(&sc->sc_resetlock);
283
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800284 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700285 ath_print(common, ATH_DBG_FATAL,
286 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200287 r = -EIO;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700288 spin_unlock_bh(&sc->rx.pcu_lock);
Gabor Juhos39892792009-06-15 17:49:09 +0200289 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800290 }
291
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700292 spin_unlock_bh(&sc->rx.pcu_lock);
293
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800294 ath_update_txpow(sc);
Pavel Roskin30691682010-03-31 18:05:31 -0400295 ath9k_hw_set_interrupts(ah, ah->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200296
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400297 if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -0400298 ath_beacon_config(sc, NULL);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400299 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
300 ath_start_ani(common);
301 }
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -0400302
Gabor Juhos39892792009-06-15 17:49:09 +0200303 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530304 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200305 return r;
Sujithff37e332008-11-24 12:07:55 +0530306}
307
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400308static void ath_paprd_activate(struct ath_softc *sc)
309{
310 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200311 struct ath9k_hw_cal_data *caldata = ah->caldata;
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700312 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400313 int chain;
314
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200315 if (!caldata || !caldata->paprd_done)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400316 return;
317
318 ath9k_ps_wakeup(sc);
Felix Fietkauddfef7922010-07-30 21:02:11 +0200319 ar9003_paprd_enable(ah, false);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400320 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700321 if (!(common->tx_chainmask & BIT(chain)))
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400322 continue;
323
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200324 ar9003_paprd_populate_single_table(ah, caldata, chain);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400325 }
326
327 ar9003_paprd_enable(ah, true);
328 ath9k_ps_restore(sc);
329}
330
331void ath_paprd_calibrate(struct work_struct *work)
332{
333 struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
334 struct ieee80211_hw *hw = sc->hw;
335 struct ath_hw *ah = sc->sc_ah;
336 struct ieee80211_hdr *hdr;
337 struct sk_buff *skb = NULL;
338 struct ieee80211_tx_info *tx_info;
339 int band = hw->conf.channel->band;
340 struct ieee80211_supported_band *sband = &sc->sbands[band];
341 struct ath_tx_control txctl;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200342 struct ath9k_hw_cal_data *caldata = ah->caldata;
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700343 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400344 int qnum, ftype;
345 int chain_ok = 0;
346 int chain;
347 int len = 1800;
348 int time_left;
349 int i;
350
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200351 if (!caldata)
352 return;
353
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400354 skb = alloc_skb(len, GFP_KERNEL);
355 if (!skb)
356 return;
357
358 tx_info = IEEE80211_SKB_CB(skb);
359
360 skb_put(skb, len);
361 memset(skb->data, 0, len);
362 hdr = (struct ieee80211_hdr *)skb->data;
363 ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
364 hdr->frame_control = cpu_to_le16(ftype);
John W. Linvillea3d3da12010-07-20 13:15:31 -0400365 hdr->duration_id = cpu_to_le16(10);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400366 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
367 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
368 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
369
370 memset(&txctl, 0, sizeof(txctl));
371 qnum = sc->tx.hwq_map[WME_AC_BE];
372 txctl.txq = &sc->tx.txq[qnum];
373
Vasanthakumar Thiagarajan47399f12010-06-24 04:09:27 -0700374 ath9k_ps_wakeup(sc);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400375 ar9003_paprd_init_table(ah);
376 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700377 if (!(common->tx_chainmask & BIT(chain)))
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400378 continue;
379
380 chain_ok = 0;
381 memset(tx_info, 0, sizeof(*tx_info));
382 tx_info->band = band;
383
384 for (i = 0; i < 4; i++) {
385 tx_info->control.rates[i].idx = sband->n_bitrates - 1;
386 tx_info->control.rates[i].count = 6;
387 }
388
389 init_completion(&sc->paprd_complete);
390 ar9003_paprd_setup_gain_table(ah, chain);
391 txctl.paprd = BIT(chain);
392 if (ath_tx_start(hw, skb, &txctl) != 0)
393 break;
394
395 time_left = wait_for_completion_timeout(&sc->paprd_complete,
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700396 msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400397 if (!time_left) {
398 ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
399 "Timeout waiting for paprd training on "
400 "TX chain %d\n",
401 chain);
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700402 goto fail_paprd;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400403 }
404
405 if (!ar9003_paprd_is_done(ah))
406 break;
407
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200408 if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400409 break;
410
411 chain_ok = 1;
412 }
413 kfree_skb(skb);
414
415 if (chain_ok) {
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200416 caldata->paprd_done = true;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400417 ath_paprd_activate(sc);
418 }
419
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700420fail_paprd:
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400421 ath9k_ps_restore(sc);
422}
423
Sujithff37e332008-11-24 12:07:55 +0530424/*
425 * This routine performs the periodic noise floor calibration function
426 * that is used to adjust and optimize the chip performance. This
427 * takes environmental changes (location, temperature) into account.
428 * When the task is complete, it reschedules itself depending on the
429 * appropriate interval that was calculated.
430 */
Sujith55624202010-01-08 10:36:02 +0530431void ath_ani_calibrate(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530432{
Sujith20977d32009-02-20 15:13:28 +0530433 struct ath_softc *sc = (struct ath_softc *)data;
434 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700435 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530436 bool longcal = false;
437 bool shortcal = false;
438 bool aniflag = false;
439 unsigned int timestamp = jiffies_to_msecs(jiffies);
Felix Fietkau60444742010-08-02 15:53:15 +0200440 u32 cal_interval, short_cal_interval, long_cal_interval;
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200441 unsigned long flags;
Felix Fietkau60444742010-08-02 15:53:15 +0200442
443 if (ah->caldata && ah->caldata->nfcal_interference)
444 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
445 else
446 long_cal_interval = ATH_LONG_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530447
Sujith20977d32009-02-20 15:13:28 +0530448 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
449 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530450
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300451 /* Only calibrate if awake */
452 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
453 goto set_timer;
454
455 ath9k_ps_wakeup(sc);
456
Sujithff37e332008-11-24 12:07:55 +0530457 /* Long calibration runs independently of short calibration. */
Felix Fietkau60444742010-08-02 15:53:15 +0200458 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530459 longcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700460 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800461 common->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530462 }
463
Sujith17d79042009-02-09 13:27:03 +0530464 /* Short calibration applies only while caldone is false */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800465 if (!common->ani.caldone) {
466 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530467 shortcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700468 ath_print(common, ATH_DBG_ANI,
469 "shortcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800470 common->ani.shortcal_timer = timestamp;
471 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530472 }
473 } else {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800474 if ((timestamp - common->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530475 ATH_RESTART_CALINTERVAL) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800476 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
477 if (common->ani.caldone)
478 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530479 }
480 }
481
482 /* Verify whether we must check ANI */
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400483 if ((timestamp - common->ani.checkani_timer) >=
484 ah->config.ani_poll_interval) {
Sujithff37e332008-11-24 12:07:55 +0530485 aniflag = true;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800486 common->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530487 }
488
489 /* Skip all processing if there's nothing to do. */
490 if (longcal || shortcal || aniflag) {
491 /* Call ANI routine if necessary */
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200492 if (aniflag) {
493 spin_lock_irqsave(&common->cc_lock, flags);
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530494 ath9k_hw_ani_monitor(ah, ah->curchan);
Felix Fietkau34300982010-10-10 18:21:52 +0200495 ath_update_survey_stats(sc);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200496 spin_unlock_irqrestore(&common->cc_lock, flags);
497 }
Sujithff37e332008-11-24 12:07:55 +0530498
499 /* Perform calibration if necessary */
500 if (longcal || shortcal) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800501 common->ani.caldone =
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700502 ath9k_hw_calibrate(ah,
503 ah->curchan,
504 common->rx_chainmask,
505 longcal);
Sujithff37e332008-11-24 12:07:55 +0530506 }
507 }
508
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300509 ath9k_ps_restore(sc);
510
Sujith20977d32009-02-20 15:13:28 +0530511set_timer:
Sujithff37e332008-11-24 12:07:55 +0530512 /*
513 * Set timer interval based on previous results.
514 * The interval must be the shortest necessary to satisfy ANI,
515 * short calibration and long calibration.
516 */
Sujithaac92072008-12-02 18:37:54 +0530517 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530518 if (sc->sc_ah->config.enable_ani)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400519 cal_interval = min(cal_interval,
520 (u32)ah->config.ani_poll_interval);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800521 if (!common->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530522 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530523
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800524 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200525 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
526 if (!ah->caldata->paprd_done)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400527 ieee80211_queue_work(sc->hw, &sc->paprd_work);
528 else
529 ath_paprd_activate(sc);
530 }
Sujithff37e332008-11-24 12:07:55 +0530531}
532
533/*
534 * Update tx/rx chainmask. For legacy association,
535 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530536 * the chainmask configuration, for bt coexistence, use
537 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530538 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200539void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530540{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700541 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700542 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700543
Felix Fietkau5ee08652010-07-31 00:11:59 +0200544 if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700545 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700546 common->tx_chainmask = ah->caps.tx_chainmask;
547 common->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530548 } else {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700549 common->tx_chainmask = 1;
550 common->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530551 }
552
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700553 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700554 "tx chmask: %d, rx chmask: %d\n",
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700555 common->tx_chainmask,
556 common->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530557}
558
559static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
560{
561 struct ath_node *an;
562
563 an = (struct ath_node *)sta->drv_priv;
564
Sujith87792ef2009-03-30 15:28:48 +0530565 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530566 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530567 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530568 sta->ht_cap.ampdu_factor);
569 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400570 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530571 }
Sujithff37e332008-11-24 12:07:55 +0530572}
573
574static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
575{
576 struct ath_node *an = (struct ath_node *)sta->drv_priv;
577
578 if (sc->sc_flags & SC_OP_TXAGGR)
579 ath_tx_node_cleanup(sc, an);
580}
581
Felix Fietkau347809f2010-07-02 00:09:52 +0200582void ath_hw_check(struct work_struct *work)
583{
584 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
585 int i;
586
587 ath9k_ps_wakeup(sc);
588
589 for (i = 0; i < 3; i++) {
590 if (ath9k_hw_check_alive(sc->sc_ah))
591 goto out;
592
593 msleep(1);
594 }
Felix Fietkaufac6b6a2010-10-23 17:45:38 +0200595 ath_reset(sc, true);
Felix Fietkau347809f2010-07-02 00:09:52 +0200596
597out:
598 ath9k_ps_restore(sc);
599}
600
Sujith55624202010-01-08 10:36:02 +0530601void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530602{
603 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700604 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700605 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700606
Sujith17d79042009-02-09 13:27:03 +0530607 u32 status = sc->intrstatus;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400608 u32 rxmask;
Sujithff37e332008-11-24 12:07:55 +0530609
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400610 ath9k_ps_wakeup(sc);
611
Felix Fietkau347809f2010-07-02 00:09:52 +0200612 if (status & ATH9K_INT_FATAL) {
Felix Fietkaufac6b6a2010-10-23 17:45:38 +0200613 ath_reset(sc, true);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400614 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530615 return;
Sujithff37e332008-11-24 12:07:55 +0530616 }
617
Felix Fietkau347809f2010-07-02 00:09:52 +0200618 if (!ath9k_hw_check_alive(ah))
619 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
620
Felix Fietkaub5c804752010-04-15 17:38:48 -0400621 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
622 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
623 ATH9K_INT_RXORN);
624 else
625 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
626
627 if (status & rxmask) {
Luis R. Rodriguezb79b33c2010-10-20 16:07:05 -0700628 spin_lock_bh(&sc->rx.pcu_lock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400629
630 /* Check for high priority Rx first */
631 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
632 (status & ATH9K_INT_RXHP))
633 ath_rx_tasklet(sc, 0, true);
634
635 ath_rx_tasklet(sc, 0, false);
Luis R. Rodriguezb79b33c2010-10-20 16:07:05 -0700636 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith063d8be2009-03-30 15:28:49 +0530637 }
638
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400639 if (status & ATH9K_INT_TX) {
640 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
641 ath_tx_edma_tasklet(sc);
642 else
643 ath_tx_tasklet(sc);
644 }
Sujith063d8be2009-03-30 15:28:49 +0530645
Gabor Juhos96148322009-07-24 17:27:21 +0200646 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300647 /*
648 * TSF sync does not look correct; remain awake to sync with
649 * the next Beacon.
650 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700651 ath_print(common, ATH_DBG_PS,
652 "TSFOOR - Sync with next Beacon\n");
Sujith1b04b932010-01-08 10:36:05 +0530653 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300654 }
655
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700656 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530657 if (status & ATH9K_INT_GENTIMER)
658 ath_gen_timer_isr(sc->sc_ah);
659
Sujithff37e332008-11-24 12:07:55 +0530660 /* re-enable hardware interrupt */
Pavel Roskin30691682010-03-31 18:05:31 -0400661 ath9k_hw_set_interrupts(ah, ah->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400662 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530663}
664
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100665irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530666{
Sujith063d8be2009-03-30 15:28:49 +0530667#define SCHED_INTR ( \
668 ATH9K_INT_FATAL | \
669 ATH9K_INT_RXORN | \
670 ATH9K_INT_RXEOL | \
671 ATH9K_INT_RX | \
Felix Fietkaub5c804752010-04-15 17:38:48 -0400672 ATH9K_INT_RXLP | \
673 ATH9K_INT_RXHP | \
Sujith063d8be2009-03-30 15:28:49 +0530674 ATH9K_INT_TX | \
675 ATH9K_INT_BMISS | \
676 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530677 ATH9K_INT_TSFOOR | \
678 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530679
Sujithff37e332008-11-24 12:07:55 +0530680 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530681 struct ath_hw *ah = sc->sc_ah;
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200682 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530683 enum ath9k_int status;
684 bool sched = false;
685
Sujith063d8be2009-03-30 15:28:49 +0530686 /*
687 * The hardware is not ready/present, don't
688 * touch anything. Note this can happen early
689 * on if the IRQ is shared.
690 */
691 if (sc->sc_flags & SC_OP_INVALID)
692 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530693
Sujithff37e332008-11-24 12:07:55 +0530694
Sujith063d8be2009-03-30 15:28:49 +0530695 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530696
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400697 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530698 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530699
Sujith063d8be2009-03-30 15:28:49 +0530700 /*
701 * Figure out the reason(s) for the interrupt. Note
702 * that the hal returns a pseudo-ISR that may include
703 * bits we haven't explicitly enabled so we mask the
704 * value to insure we only process bits we requested.
705 */
706 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
Pavel Roskin30691682010-03-31 18:05:31 -0400707 status &= ah->imask; /* discard unasked-for bits */
Sujith063d8be2009-03-30 15:28:49 +0530708
709 /*
710 * If there are no status bits set, then this interrupt was not
711 * for me (should have been caught above).
712 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400713 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530714 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530715
716 /* Cache the status */
717 sc->intrstatus = status;
718
719 if (status & SCHED_INTR)
720 sched = true;
721
722 /*
723 * If a FATAL or RXORN interrupt is received, we have to reset the
724 * chip immediately.
725 */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400726 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
727 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
Sujith063d8be2009-03-30 15:28:49 +0530728 goto chip_reset;
729
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400730 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
731 (status & ATH9K_INT_BB_WATCHDOG)) {
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200732
733 spin_lock(&common->cc_lock);
734 ath_hw_cycle_counters_update(common);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400735 ar9003_hw_bb_watchdog_dbg_info(ah);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200736 spin_unlock(&common->cc_lock);
737
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400738 goto chip_reset;
739 }
740
Sujith063d8be2009-03-30 15:28:49 +0530741 if (status & ATH9K_INT_SWBA)
742 tasklet_schedule(&sc->bcon_tasklet);
743
744 if (status & ATH9K_INT_TXURN)
745 ath9k_hw_updatetxtriglevel(ah, true);
746
Felix Fietkaub5c804752010-04-15 17:38:48 -0400747 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
748 if (status & ATH9K_INT_RXEOL) {
749 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
750 ath9k_hw_set_interrupts(ah, ah->imask);
751 }
752 }
753
Sujith063d8be2009-03-30 15:28:49 +0530754 if (status & ATH9K_INT_MIB) {
755 /*
756 * Disable interrupts until we service the MIB
757 * interrupt; otherwise it will continue to
758 * fire.
759 */
760 ath9k_hw_set_interrupts(ah, 0);
761 /*
762 * Let the hal handle the event. We assume
763 * it will clear whatever condition caused
764 * the interrupt.
765 */
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200766 spin_lock(&common->cc_lock);
Felix Fietkaubfc472b2010-10-04 20:09:48 +0200767 ath9k_hw_proc_mib_event(ah);
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200768 spin_unlock(&common->cc_lock);
Pavel Roskin30691682010-03-31 18:05:31 -0400769 ath9k_hw_set_interrupts(ah, ah->imask);
Sujith063d8be2009-03-30 15:28:49 +0530770 }
771
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400772 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
773 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530774 /* Clear RxAbort bit so that we can
775 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700776 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400777 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530778 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith063d8be2009-03-30 15:28:49 +0530779 }
Sujith063d8be2009-03-30 15:28:49 +0530780
781chip_reset:
782
Sujith817e11d2008-12-07 21:42:44 +0530783 ath_debug_stat_interrupt(sc, status);
784
Sujithff37e332008-11-24 12:07:55 +0530785 if (sched) {
786 /* turn off every interrupt except SWBA */
Pavel Roskin30691682010-03-31 18:05:31 -0400787 ath9k_hw_set_interrupts(ah, (ah->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530788 tasklet_schedule(&sc->intr_tq);
789 }
790
791 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530792
793#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530794}
795
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530797 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530798 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799{
800 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700801
802 switch (chan->band) {
803 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530804 switch(channel_type) {
805 case NL80211_CHAN_NO_HT:
806 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700807 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530808 break;
809 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700810 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530811 break;
812 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530814 break;
815 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 break;
817 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530818 switch(channel_type) {
819 case NL80211_CHAN_NO_HT:
820 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700821 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530822 break;
823 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700824 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530825 break;
826 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530828 break;
829 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700830 break;
831 default:
832 break;
833 }
834
835 return chanmode;
836}
837
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530838static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530839 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530840 struct ieee80211_bss_conf *bss_conf)
841{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700842 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700843 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530844
845 if (bss_conf->assoc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700846 ath_print(common, ATH_DBG_CONFIG,
847 "Bss Info ASSOC %d, bssid: %pM\n",
848 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530849
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530850 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700851 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700852 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300853
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530854 /*
855 * Request a re-configuration of Beacon related timers
856 * on the receipt of the first Beacon frame (i.e.,
857 * after time sync with the AP).
858 */
Sujith1b04b932010-01-08 10:36:05 +0530859 sc->ps_flags |= PS_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530860
861 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200862 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530863
864 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530865 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530866
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -0700867 sc->sc_flags |= SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800868 ath_start_ani(common);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530869 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700870 ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700871 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +0530872 /* Stop ANI */
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -0700873 sc->sc_flags &= ~SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800874 del_timer_sync(&common->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530875 }
876}
877
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800878void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530879{
Sujithcbe61d82009-02-09 13:27:12 +0530880 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700881 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800882 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800883 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530884
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530885 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530886 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +0530887
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530888 if (!ah->curchan)
889 ah->curchan = ath_get_curchannel(sc, sc->hw);
890
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700891 spin_lock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530892 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200893 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800894 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700895 ath_print(common, ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500896 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700897 "reset status %d\n",
898 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530899 }
900 spin_unlock_bh(&sc->sc_resetlock);
901
902 ath_update_txpow(sc);
903 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700904 ath_print(common, ATH_DBG_FATAL,
905 "Unable to restart recv logic\n");
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700906 spin_unlock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530907 return;
908 }
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700909 spin_unlock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530910
911 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200912 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530913
914 /* Re-Enable interrupts */
Pavel Roskin30691682010-03-31 18:05:31 -0400915 ath9k_hw_set_interrupts(ah, ah->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530916
917 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530918 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530919 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530920 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530921
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800922 ieee80211_wake_queues(hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530923 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530924}
925
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800926void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530927{
Sujithcbe61d82009-02-09 13:27:12 +0530928 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800929 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800930 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530931
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530932 ath9k_ps_wakeup(sc);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800933 ieee80211_stop_queues(hw);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530934
Vivek Natarajan982723d2010-06-23 12:08:29 +0530935 /*
936 * Keep the LED on when the radio is disabled
937 * during idle unassociated state.
938 */
939 if (!sc->ps_idle) {
940 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
941 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
942 }
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530943
944 /* Disable interrupts */
945 ath9k_hw_set_interrupts(ah, 0);
946
Sujith043a0402009-01-16 21:38:47 +0530947 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700948
949 spin_lock_bh(&sc->rx.pcu_lock);
950
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530951 ath_stoprecv(sc); /* turn off frame recv */
952 ath_flushrecv(sc); /* flush recv queue */
953
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530954 if (!ah->curchan)
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800955 ah->curchan = ath_get_curchannel(sc, hw);
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530956
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530957 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200958 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800959 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700960 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500961 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700962 "reset status %d\n",
963 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530964 }
965 spin_unlock_bh(&sc->sc_resetlock);
966
967 ath9k_hw_phy_disable(ah);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700968
969 spin_unlock_bh(&sc->rx.pcu_lock);
970
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530971 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530972 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700973 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530974}
975
Sujithff37e332008-11-24 12:07:55 +0530976int ath_reset(struct ath_softc *sc, bool retry_tx)
977{
Sujithcbe61d82009-02-09 13:27:12 +0530978 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700979 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800980 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800981 int r;
Sujithff37e332008-11-24 12:07:55 +0530982
Sujith2ab81d42009-12-14 16:34:56 +0530983 /* Stop ANI */
984 del_timer_sync(&common->ani.timer);
985
Sujithcc9c3782010-01-08 10:36:09 +0530986 ieee80211_stop_queues(hw);
987
Sujithff37e332008-11-24 12:07:55 +0530988 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530989 ath_drain_all_txq(sc, retry_tx);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700990
991 spin_lock_bh(&sc->rx.pcu_lock);
992
Sujithff37e332008-11-24 12:07:55 +0530993 ath_stoprecv(sc);
994 ath_flushrecv(sc);
995
996 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200997 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800998 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700999 ath_print(common, ATH_DBG_FATAL,
1000 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301001 spin_unlock_bh(&sc->sc_resetlock);
1002
1003 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001004 ath_print(common, ATH_DBG_FATAL,
1005 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301006
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001007 spin_unlock_bh(&sc->rx.pcu_lock);
1008
Sujithff37e332008-11-24 12:07:55 +05301009 /*
1010 * We may be doing a reset in response to a request
1011 * that changes the channel so update any state that
1012 * might change as a result.
1013 */
Sujithff37e332008-11-24 12:07:55 +05301014 ath_update_txpow(sc);
1015
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -04001016 if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001017 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301018
Pavel Roskin30691682010-03-31 18:05:31 -04001019 ath9k_hw_set_interrupts(ah, ah->imask);
Sujithff37e332008-11-24 12:07:55 +05301020
1021 if (retry_tx) {
1022 int i;
1023 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1024 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301025 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1026 ath_txq_schedule(sc, &sc->tx.txq[i]);
1027 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301028 }
1029 }
1030 }
1031
Sujithcc9c3782010-01-08 10:36:09 +05301032 ieee80211_wake_queues(hw);
1033
Sujith2ab81d42009-12-14 16:34:56 +05301034 /* Start ANI */
1035 ath_start_ani(common);
1036
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001037 return r;
Sujithff37e332008-11-24 12:07:55 +05301038}
1039
Felix Fietkauebe297c2010-06-12 00:33:53 -04001040static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
Sujithff37e332008-11-24 12:07:55 +05301041{
1042 int qnum;
1043
1044 switch (queue) {
1045 case 0:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001046 qnum = sc->tx.hwq_map[WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301047 break;
1048 case 1:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001049 qnum = sc->tx.hwq_map[WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301050 break;
1051 case 2:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001052 qnum = sc->tx.hwq_map[WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301053 break;
1054 case 3:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001055 qnum = sc->tx.hwq_map[WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301056 break;
1057 default:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001058 qnum = sc->tx.hwq_map[WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301059 break;
1060 }
1061
1062 return qnum;
1063}
1064
1065int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1066{
1067 int qnum;
1068
1069 switch (queue) {
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001070 case WME_AC_VO:
Sujithff37e332008-11-24 12:07:55 +05301071 qnum = 0;
1072 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001073 case WME_AC_VI:
Sujithff37e332008-11-24 12:07:55 +05301074 qnum = 1;
1075 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001076 case WME_AC_BE:
Sujithff37e332008-11-24 12:07:55 +05301077 qnum = 2;
1078 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001079 case WME_AC_BK:
Sujithff37e332008-11-24 12:07:55 +05301080 qnum = 3;
1081 break;
1082 default:
1083 qnum = -1;
1084 break;
1085 }
1086
1087 return qnum;
1088}
1089
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001090/* XXX: Remove me once we don't depend on ath9k_channel for all
1091 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001092void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1093 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001094{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001095 struct ieee80211_channel *chan = hw->conf.channel;
1096 struct ieee80211_conf *conf = &hw->conf;
1097
1098 ichan->channel = chan->center_freq;
1099 ichan->chan = chan;
1100
1101 if (chan->band == IEEE80211_BAND_2GHZ) {
1102 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05301103 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001104 } else {
1105 ichan->chanmode = CHANNEL_A;
1106 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1107 }
1108
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001109 if (conf_is_ht(conf))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001110 ichan->chanmode = ath_get_extchanmode(sc, chan,
1111 conf->channel_type);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001112}
1113
Sujithff37e332008-11-24 12:07:55 +05301114/**********************/
1115/* mac80211 callbacks */
1116/**********************/
1117
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001118static int ath9k_start(struct ieee80211_hw *hw)
1119{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001120 struct ath_wiphy *aphy = hw->priv;
1121 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001122 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001123 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001124 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301125 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301126 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001127
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001128 ath_print(common, ATH_DBG_CONFIG,
1129 "Starting driver with initial channel: %d MHz\n",
1130 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001131
Sujith141b38b2009-02-04 08:10:07 +05301132 mutex_lock(&sc->mutex);
1133
Jouni Malinen9580a222009-03-03 19:23:33 +02001134 if (ath9k_wiphy_started(sc)) {
1135 if (sc->chan_idx == curchan->hw_value) {
1136 /*
1137 * Already on the operational channel, the new wiphy
1138 * can be marked active.
1139 */
1140 aphy->state = ATH_WIPHY_ACTIVE;
1141 ieee80211_wake_queues(hw);
1142 } else {
1143 /*
1144 * Another wiphy is on another channel, start the new
1145 * wiphy in paused state.
1146 */
1147 aphy->state = ATH_WIPHY_PAUSED;
1148 ieee80211_stop_queues(hw);
1149 }
1150 mutex_unlock(&sc->mutex);
1151 return 0;
1152 }
1153 aphy->state = ATH_WIPHY_ACTIVE;
1154
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001155 /* setup initial channel */
1156
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301157 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001158
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301159 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001160
Sujithff37e332008-11-24 12:07:55 +05301161 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001162 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05301163
1164 /*
1165 * The basic interface to setting the hardware in a good
1166 * state is ``reset''. On return the hardware is known to
1167 * be powered up and with interrupts disabled. This must
1168 * be followed by initialization of the appropriate bits
1169 * and then setup of the interrupt mask.
1170 */
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001171 spin_lock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301172 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001173 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001174 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001175 ath_print(common, ATH_DBG_FATAL,
1176 "Unable to reset hardware; reset status %d "
1177 "(freq %u MHz)\n", r,
1178 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05301179 spin_unlock_bh(&sc->sc_resetlock);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001180 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith141b38b2009-02-04 08:10:07 +05301181 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001182 }
Sujithff37e332008-11-24 12:07:55 +05301183 spin_unlock_bh(&sc->sc_resetlock);
1184
1185 /*
1186 * This is needed only to setup initial state
1187 * but it's best done after a reset.
1188 */
1189 ath_update_txpow(sc);
1190
1191 /*
1192 * Setup the hardware after reset:
1193 * The receive engine is set going.
1194 * Frame transmit is handled entirely
1195 * in the frame output path; there's nothing to do
1196 * here except setup the interrupt mask.
1197 */
1198 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001199 ath_print(common, ATH_DBG_FATAL,
1200 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05301201 r = -EIO;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001202 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith141b38b2009-02-04 08:10:07 +05301203 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05301204 }
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001205 spin_unlock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301206
1207 /* Setup our intr mask. */
Felix Fietkaub5c804752010-04-15 17:38:48 -04001208 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
1209 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
1210 ATH9K_INT_GLOBAL;
1211
1212 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Luis R. Rodriguez08578b82010-05-13 13:33:44 -04001213 ah->imask |= ATH9K_INT_RXHP |
1214 ATH9K_INT_RXLP |
1215 ATH9K_INT_BB_WATCHDOG;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001216 else
1217 ah->imask |= ATH9K_INT_RX;
Sujithff37e332008-11-24 12:07:55 +05301218
Felix Fietkau364734f2010-09-14 20:22:44 +02001219 ah->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05301220
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001221 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Pavel Roskin30691682010-03-31 18:05:31 -04001222 ah->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05301223
Sujithff37e332008-11-24 12:07:55 +05301224 sc->sc_flags &= ~SC_OP_INVALID;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301225 sc->sc_ah->is_monitoring = false;
Sujithff37e332008-11-24 12:07:55 +05301226
1227 /* Disable BMISS interrupt when we're not associated */
Pavel Roskin30691682010-03-31 18:05:31 -04001228 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1229 ath9k_hw_set_interrupts(ah, ah->imask);
Sujithff37e332008-11-24 12:07:55 +05301230
Jouni Malinenbce048d2009-03-03 19:23:28 +02001231 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001232
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001233 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001234
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001235 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
1236 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07001237 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1238 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001239 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05301240
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001241 if (common->bus_ops->bt_coex_prep)
1242 common->bus_ops->bt_coex_prep(common);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001243 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001244 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301245 }
1246
Gabor Juhos98c316e2010-11-25 18:26:07 +01001247 pm_qos_update_request(&sc->pm_qos_req, 55);
Vivek Natarajan10598c12010-10-30 22:05:13 +05301248
Sujith141b38b2009-02-04 08:10:07 +05301249mutex_unlock:
1250 mutex_unlock(&sc->mutex);
1251
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001252 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001253}
1254
1255static int ath9k_tx(struct ieee80211_hw *hw,
1256 struct sk_buff *skb)
1257{
Jouni Malinen147583c2008-08-11 14:01:50 +03001258 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02001259 struct ath_wiphy *aphy = hw->priv;
1260 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001261 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05301262 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +01001263 int padpos, padsize;
1264 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Felix Fietkau84642d62010-06-01 21:33:13 +02001265 int qnum;
Sujith528f0c62008-10-29 10:14:26 +05301266
Jouni Malinen8089cc42009-03-03 19:23:38 +02001267 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001268 ath_print(common, ATH_DBG_XMIT,
1269 "ath9k: %s: TX in unexpected wiphy state "
1270 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02001271 goto exit;
1272 }
1273
Gabor Juhos96148322009-07-24 17:27:21 +02001274 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03001275 /*
1276 * mac80211 does not set PM field for normal data frames, so we
1277 * need to update that based on the current PS mode.
1278 */
1279 if (ieee80211_is_data(hdr->frame_control) &&
1280 !ieee80211_is_nullfunc(hdr->frame_control) &&
1281 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001282 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
1283 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03001284 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1285 }
1286 }
1287
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001288 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
1289 /*
1290 * We are using PS-Poll and mac80211 can request TX while in
1291 * power save mode. Need to wake up hardware for the TX to be
1292 * completed and if needed, also for RX of buffered frames.
1293 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001294 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001295 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1296 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001297 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001298 ath_print(common, ATH_DBG_PS,
1299 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +05301300 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001301 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001302 ath_print(common, ATH_DBG_PS,
1303 "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +05301304 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001305 }
1306 /*
1307 * The actual restore operation will happen only after
1308 * the sc_flags bit is cleared. We are just dropping
1309 * the ps_usecount here.
1310 */
1311 ath9k_ps_restore(sc);
1312 }
1313
Sujith528f0c62008-10-29 10:14:26 +05301314 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03001315
1316 /*
1317 * As a temporary workaround, assign seq# here; this will likely need
1318 * to be cleaned up to work better with Beacon transmission and virtual
1319 * BSSes.
1320 */
1321 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Jouni Malinen147583c2008-08-11 14:01:50 +03001322 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05301323 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03001324 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05301325 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03001326 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001327
1328 /* Add the padding after the header if this is not already done */
Benoit Papillault1bc14882009-11-24 15:49:18 +01001329 padpos = ath9k_cmn_padpos(hdr->frame_control);
1330 padsize = padpos & 3;
1331 if (padsize && skb->len>padpos) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001332 if (skb_headroom(skb) < padsize)
1333 return -1;
1334 skb_push(skb, padsize);
Benoit Papillault1bc14882009-11-24 15:49:18 +01001335 memmove(skb->data, skb->data + padsize, padpos);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001336 }
1337
Felix Fietkau84642d62010-06-01 21:33:13 +02001338 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
1339 txctl.txq = &sc->tx.txq[qnum];
Sujith528f0c62008-10-29 10:14:26 +05301340
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001341 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001342
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001343 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001344 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05301345 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001346 }
1347
1348 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301349exit:
1350 dev_kfree_skb_any(skb);
1351 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001352}
1353
1354static void ath9k_stop(struct ieee80211_hw *hw)
1355{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001356 struct ath_wiphy *aphy = hw->priv;
1357 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001358 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001359 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan447a42c2010-07-08 12:12:29 +05301360 int i;
Sujith9c84b792008-10-29 10:17:13 +05301361
Sujith4c483812009-08-18 10:51:52 +05301362 mutex_lock(&sc->mutex);
1363
Jouni Malinen9580a222009-03-03 19:23:33 +02001364 aphy->state = ATH_WIPHY_INACTIVE;
1365
Vivek Natarajan9a75c2f2010-06-22 11:52:37 +05301366 if (led_blink)
1367 cancel_delayed_work_sync(&sc->ath_led_blink_work);
1368
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001369 cancel_delayed_work_sync(&sc->tx_complete_work);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04001370 cancel_work_sync(&sc->paprd_work);
Felix Fietkau347809f2010-07-02 00:09:52 +02001371 cancel_work_sync(&sc->hw_check_work);
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001372
Rajkumar Manoharan447a42c2010-07-08 12:12:29 +05301373 for (i = 0; i < sc->num_sec_wiphy; i++) {
1374 if (sc->sec_wiphy[i])
1375 break;
1376 }
1377
1378 if (i == sc->num_sec_wiphy) {
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001379 cancel_delayed_work_sync(&sc->wiphy_work);
1380 cancel_work_sync(&sc->chan_work);
1381 }
1382
Sujith9c84b792008-10-29 10:17:13 +05301383 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001384 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05301385 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05301386 return;
1387 }
1388
Jouni Malinen9580a222009-03-03 19:23:33 +02001389 if (ath9k_wiphy_started(sc)) {
1390 mutex_unlock(&sc->mutex);
1391 return; /* another wiphy still in use */
1392 }
1393
Sujith3867cf62009-12-23 20:03:27 -05001394 /* Ensure HW is awake when we try to shut it down. */
1395 ath9k_ps_wakeup(sc);
1396
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001397 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001398 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001399 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001400 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301401 }
1402
Sujithff37e332008-11-24 12:07:55 +05301403 /* make sure h/w will not generate any interrupt
1404 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001405 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05301406
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001407 spin_lock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301408 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05301409 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05301410 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001411 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05301412 } else
Sujithb77f4832008-12-07 21:44:03 +05301413 sc->rx.rxlink = NULL;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001414 spin_unlock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301415
Sujithff37e332008-11-24 12:07:55 +05301416 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001417 ath9k_hw_disable(ah);
1418 ath9k_hw_configpcipowersave(ah, 1, 1);
Sujith3867cf62009-12-23 20:03:27 -05001419 ath9k_ps_restore(sc);
1420
1421 /* Finally, put the chip in FULL SLEEP mode */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001422 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05301423
1424 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001425
Gabor Juhos98c316e2010-11-25 18:26:07 +01001426 pm_qos_update_request(&sc->pm_qos_req, PM_QOS_DEFAULT_VALUE);
Vivek Natarajan10598c12010-10-30 22:05:13 +05301427
Sujith141b38b2009-02-04 08:10:07 +05301428 mutex_unlock(&sc->mutex);
1429
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001430 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001431}
1432
1433static int ath9k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001434 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001435{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001436 struct ath_wiphy *aphy = hw->priv;
1437 struct ath_softc *sc = aphy->sc;
Pavel Roskin30691682010-03-31 18:05:31 -04001438 struct ath_hw *ah = sc->sc_ah;
1439 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001440 struct ath_vif *avp = (void *)vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08001441 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001442 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001443
Sujith141b38b2009-02-04 08:10:07 +05301444 mutex_lock(&sc->mutex);
1445
Johannes Berg1ed32e42009-12-23 13:15:45 +01001446 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001447 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08001448 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001449 break;
Bill Jordane51f3ef2010-10-01 11:20:39 -04001450 case NL80211_IFTYPE_WDS:
1451 ic_opmode = NL80211_IFTYPE_WDS;
1452 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001453 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02001454 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04001455 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001456 if (sc->nbcnvifs >= ATH_BCBUF) {
1457 ret = -ENOBUFS;
1458 goto out;
1459 }
Johannes Berg1ed32e42009-12-23 13:15:45 +01001460 ic_opmode = vif->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001461 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001463 ath_print(common, ATH_DBG_FATAL,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001464 "Interface type %d not yet supported\n", vif->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001465 ret = -EOPNOTSUPP;
1466 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467 }
1468
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001469 ath_print(common, ATH_DBG_CONFIG,
1470 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001471
Sujith17d79042009-02-09 13:27:03 +05301472 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05301473 avp->av_opmode = ic_opmode;
1474 avp->av_bslot = -1;
1475
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001476 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001477
Felix Fietkau364734f2010-09-14 20:22:44 +02001478 ath9k_set_bssid_mask(hw, vif);
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001479
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001480 if (sc->nvifs > 1)
1481 goto out; /* skip global settings for secondary vif */
1482
Sujithb238e902009-03-03 10:16:56 +05301483 if (ic_opmode == NL80211_IFTYPE_AP) {
Pavel Roskin30691682010-03-31 18:05:31 -04001484 ath9k_hw_set_tsfadjust(ah, 1);
Sujithb238e902009-03-03 10:16:56 +05301485 sc->sc_flags |= SC_OP_TSF_RESET;
1486 }
Sujith5640b082008-10-29 10:16:06 +05301487
Sujith5640b082008-10-29 10:16:06 +05301488 /* Set the device opmode */
Pavel Roskin30691682010-03-31 18:05:31 -04001489 ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05301490
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301491 /*
1492 * Enable MIB interrupts when there are hardware phy counters.
1493 * Note we only do this (at the moment) for station mode.
1494 */
Johannes Berg1ed32e42009-12-23 13:15:45 +01001495 if ((vif->type == NL80211_IFTYPE_STATION) ||
1496 (vif->type == NL80211_IFTYPE_ADHOC) ||
1497 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez3448f912010-04-15 17:38:23 -04001498 if (ah->config.enable_ani)
1499 ah->imask |= ATH9K_INT_MIB;
Pavel Roskin30691682010-03-31 18:05:31 -04001500 ah->imask |= ATH9K_INT_TSFOOR;
Sujith4af9cf42009-02-12 10:06:47 +05301501 }
1502
Pavel Roskin30691682010-03-31 18:05:31 -04001503 ath9k_hw_set_interrupts(ah, ah->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301504
Johannes Berg1ed32e42009-12-23 13:15:45 +01001505 if (vif->type == NL80211_IFTYPE_AP ||
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301506 vif->type == NL80211_IFTYPE_ADHOC) {
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001507 sc->sc_flags |= SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001508 ath_start_ani(common);
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001509 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001510
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001511out:
Sujith141b38b2009-02-04 08:10:07 +05301512 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001513 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001514}
1515
1516static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001517 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001518{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001519 struct ath_wiphy *aphy = hw->priv;
1520 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001521 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001522 struct ath_vif *avp = (void *)vif->drv_priv;
Rajkumar Manoharan46047782010-11-26 23:24:31 +05301523 bool bs_valid = false;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001524 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001525
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001526 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001527
Sujith141b38b2009-02-04 08:10:07 +05301528 mutex_lock(&sc->mutex);
1529
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001530 /* Stop ANI */
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001531 sc->sc_flags &= ~SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001532 del_timer_sync(&common->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001533
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001534 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04001535 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
1536 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
1537 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001538 ath9k_ps_wakeup(sc);
Sujithb77f4832008-12-07 21:44:03 +05301539 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001540 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001541 }
1542
Felix Fietkau74401772010-01-19 20:51:32 +01001543 ath_beacon_return(sc, avp);
Sujith672840a2008-08-11 14:05:08 +05301544 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001545
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001546 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Johannes Berg1ed32e42009-12-23 13:15:45 +01001547 if (sc->beacon.bslot[i] == vif) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001548 printk(KERN_DEBUG "%s: vif had allocated beacon "
1549 "slot\n", __func__);
1550 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001551 sc->beacon.bslot_aphy[i] = NULL;
Rajkumar Manoharan46047782010-11-26 23:24:31 +05301552 } else if (sc->beacon.bslot[i])
1553 bs_valid = true;
1554 }
1555 if (!bs_valid && (sc->sc_ah->imask & ATH9K_INT_SWBA)) {
1556 /* Disable SWBA interrupt */
1557 sc->sc_ah->imask &= ~ATH9K_INT_SWBA;
1558 ath9k_ps_wakeup(sc);
1559 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_ah->imask);
1560 ath9k_ps_restore(sc);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001561 }
1562
Sujith17d79042009-02-09 13:27:03 +05301563 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05301564
1565 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001566}
1567
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301568static void ath9k_enable_ps(struct ath_softc *sc)
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301569{
Pavel Roskin30691682010-03-31 18:05:31 -04001570 struct ath_hw *ah = sc->sc_ah;
1571
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301572 sc->ps_enabled = true;
Pavel Roskin30691682010-03-31 18:05:31 -04001573 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1574 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1575 ah->imask |= ATH9K_INT_TIM_TIMER;
1576 ath9k_hw_set_interrupts(ah, ah->imask);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301577 }
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001578 ath9k_hw_setrxabort(ah, 1);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301579 }
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301580}
1581
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301582static void ath9k_disable_ps(struct ath_softc *sc)
1583{
1584 struct ath_hw *ah = sc->sc_ah;
1585
1586 sc->ps_enabled = false;
1587 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1588 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1589 ath9k_hw_setrxabort(ah, 0);
1590 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1591 PS_WAIT_FOR_CAB |
1592 PS_WAIT_FOR_PSPOLL_DATA |
1593 PS_WAIT_FOR_TX_ACK);
1594 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1595 ah->imask &= ~ATH9K_INT_TIM_TIMER;
1596 ath9k_hw_set_interrupts(ah, ah->imask);
1597 }
1598 }
1599
1600}
1601
Johannes Berge8975582008-10-09 12:18:51 +02001602static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001603{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001604 struct ath_wiphy *aphy = hw->priv;
1605 struct ath_softc *sc = aphy->sc;
Felix Fietkau34300982010-10-10 18:21:52 +02001606 struct ath_hw *ah = sc->sc_ah;
1607 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berge8975582008-10-09 12:18:51 +02001608 struct ieee80211_conf *conf = &hw->conf;
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001609 bool disable_radio;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001610
Sujithaa33de02008-12-18 11:40:16 +05301611 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301612
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001613 /*
1614 * Leave this as the first check because we need to turn on the
1615 * radio if it was disabled before prior to processing the rest
1616 * of the changes. Likewise we must only disable the radio towards
1617 * the end.
1618 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001619 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001620 bool enable_radio;
1621 bool all_wiphys_idle;
1622 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001623
1624 spin_lock_bh(&sc->wiphy_lock);
1625 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001626 ath9k_set_wiphy_idle(aphy, idle);
1627
Felix Fietkau11446012010-04-06 12:05:01 -07001628 enable_radio = (!idle && all_wiphys_idle);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001629
1630 /*
1631 * After we unlock here its possible another wiphy
1632 * can be re-renabled so to account for that we will
1633 * only disable the radio toward the end of this routine
1634 * if by then all wiphys are still idle.
1635 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001636 spin_unlock_bh(&sc->wiphy_lock);
1637
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001638 if (enable_radio) {
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +05301639 sc->ps_idle = false;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001640 ath_radio_enable(sc, hw);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001641 ath_print(common, ATH_DBG_CONFIG,
1642 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001643 }
1644 }
1645
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001646 /*
1647 * We just prepare to enable PS. We have to wait until our AP has
1648 * ACK'd our null data frame to disable RX otherwise we'll ignore
1649 * those ACKs and end up retransmitting the same null data frames.
1650 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1651 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301652 if (changed & IEEE80211_CONF_CHANGE_PS) {
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001653 unsigned long flags;
1654 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301655 if (conf->flags & IEEE80211_CONF_PS)
1656 ath9k_enable_ps(sc);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301657 else
1658 ath9k_disable_ps(sc);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001659 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301660 }
1661
Sujith199afd92010-01-08 10:36:13 +05301662 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1663 if (conf->flags & IEEE80211_CONF_MONITOR) {
1664 ath_print(common, ATH_DBG_CONFIG,
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301665 "Monitor mode is enabled\n");
1666 sc->sc_ah->is_monitoring = true;
1667 } else {
1668 ath_print(common, ATH_DBG_CONFIG,
1669 "Monitor mode is disabled\n");
1670 sc->sc_ah->is_monitoring = false;
Sujith199afd92010-01-08 10:36:13 +05301671 }
1672 }
1673
Johannes Berg47979382009-01-07 10:13:27 +01001674 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05301675 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001676 int pos = curchan->hw_value;
Felix Fietkau34300982010-10-10 18:21:52 +02001677 int old_pos = -1;
1678 unsigned long flags;
1679
1680 if (ah->curchan)
1681 old_pos = ah->curchan - &ah->channels[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001683 aphy->chan_idx = pos;
1684 aphy->chan_is_ht = conf_is_ht(conf);
Felix Fietkau5ee08652010-07-31 00:11:59 +02001685 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
1686 sc->sc_flags |= SC_OP_OFFCHANNEL;
1687 else
1688 sc->sc_flags &= ~SC_OP_OFFCHANNEL;
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001689
Jouni Malinen8089cc42009-03-03 19:23:38 +02001690 if (aphy->state == ATH_WIPHY_SCAN ||
1691 aphy->state == ATH_WIPHY_ACTIVE)
1692 ath9k_wiphy_pause_all_forced(sc, aphy);
1693 else {
1694 /*
1695 * Do not change operational channel based on a paused
1696 * wiphy changes.
1697 */
1698 goto skip_chan_change;
1699 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001700
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001701 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1702 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02001703
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001704 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001705 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05301706
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08001707 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05301708
Felix Fietkau34300982010-10-10 18:21:52 +02001709 /* update survey stats for the old channel before switching */
1710 spin_lock_irqsave(&common->cc_lock, flags);
1711 ath_update_survey_stats(sc);
1712 spin_unlock_irqrestore(&common->cc_lock, flags);
1713
1714 /*
1715 * If the operating channel changes, change the survey in-use flags
1716 * along with it.
1717 * Reset the survey data for the new channel, unless we're switching
1718 * back to the operating channel from an off-channel operation.
1719 */
1720 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1721 sc->cur_survey != &sc->survey[pos]) {
1722
1723 if (sc->cur_survey)
1724 sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
1725
1726 sc->cur_survey = &sc->survey[pos];
1727
1728 memset(sc->cur_survey, 0, sizeof(struct survey_info));
1729 sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
1730 } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
1731 memset(&sc->survey[pos], 0, sizeof(struct survey_info));
1732 }
1733
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001734 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001735 ath_print(common, ATH_DBG_FATAL,
1736 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301737 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05301738 return -EINVAL;
1739 }
Felix Fietkau34300982010-10-10 18:21:52 +02001740
1741 /*
1742 * The most recent snapshot of channel->noisefloor for the old
1743 * channel is only available after the hardware reset. Copy it to
1744 * the survey stats now.
1745 */
1746 if (old_pos >= 0)
1747 ath_update_survey_nf(sc, old_pos);
Sujith094d05d2008-12-12 11:57:43 +05301748 }
Sujith86b89ee2008-08-07 10:54:57 +05301749
Jouni Malinen8089cc42009-03-03 19:23:38 +02001750skip_chan_change:
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001751 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Sujith17d79042009-02-09 13:27:03 +05301752 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001753 ath_update_txpow(sc);
1754 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001755
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001756 spin_lock_bh(&sc->wiphy_lock);
1757 disable_radio = ath9k_all_wiphys_idle(sc);
1758 spin_unlock_bh(&sc->wiphy_lock);
1759
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001760 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001761 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +05301762 sc->ps_idle = true;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001763 ath_radio_disable(sc, hw);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001764 }
1765
Sujithaa33de02008-12-18 11:40:16 +05301766 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301767
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001768 return 0;
1769}
1770
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001771#define SUPPORTED_FILTERS \
1772 (FIF_PROMISC_IN_BSS | \
1773 FIF_ALLMULTI | \
1774 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001775 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001776 FIF_OTHER_BSS | \
1777 FIF_BCN_PRBRESP_PROMISC | \
Jouni Malinen9c1d8e42010-10-13 17:29:31 +03001778 FIF_PROBE_REQ | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001779 FIF_FCSFAIL)
1780
Sujith7dcfdcd2008-08-11 14:03:13 +05301781/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001782static void ath9k_configure_filter(struct ieee80211_hw *hw,
1783 unsigned int changed_flags,
1784 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001785 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001786{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001787 struct ath_wiphy *aphy = hw->priv;
1788 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05301789 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001790
1791 changed_flags &= SUPPORTED_FILTERS;
1792 *total_flags &= SUPPORTED_FILTERS;
1793
Sujithb77f4832008-12-07 21:44:03 +05301794 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001795 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301796 rfilt = ath_calcrxfilter(sc);
1797 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001798 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301799
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001800 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
1801 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001802}
1803
Johannes Berg4ca77862010-02-19 19:06:56 +01001804static int ath9k_sta_add(struct ieee80211_hw *hw,
1805 struct ieee80211_vif *vif,
1806 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001807{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001808 struct ath_wiphy *aphy = hw->priv;
1809 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001810
Johannes Berg4ca77862010-02-19 19:06:56 +01001811 ath_node_attach(sc, sta);
1812
1813 return 0;
1814}
1815
1816static int ath9k_sta_remove(struct ieee80211_hw *hw,
1817 struct ieee80211_vif *vif,
1818 struct ieee80211_sta *sta)
1819{
1820 struct ath_wiphy *aphy = hw->priv;
1821 struct ath_softc *sc = aphy->sc;
1822
1823 ath_node_detach(sc, sta);
1824
1825 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001826}
1827
Sujith141b38b2009-02-04 08:10:07 +05301828static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001829 const struct ieee80211_tx_queue_params *params)
1830{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001831 struct ath_wiphy *aphy = hw->priv;
1832 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001833 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05301834 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001835 int ret = 0, qnum;
1836
1837 if (queue >= WME_NUM_AC)
1838 return 0;
1839
Sujith141b38b2009-02-04 08:10:07 +05301840 mutex_lock(&sc->mutex);
1841
Sujith1ffb0612009-03-30 15:28:46 +05301842 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1843
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001844 qi.tqi_aifs = params->aifs;
1845 qi.tqi_cwmin = params->cw_min;
1846 qi.tqi_cwmax = params->cw_max;
1847 qi.tqi_burstTime = params->txop;
1848 qnum = ath_get_hal_qnum(queue, sc);
1849
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001850 ath_print(common, ATH_DBG_CONFIG,
1851 "Configure tx [queue/halq] [%d/%d], "
1852 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1853 queue, qnum, params->aifs, params->cw_min,
1854 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001855
1856 ret = ath_txq_update(sc, qnum, &qi);
1857 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001858 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859
Vivek Natarajan94db2932009-11-25 12:01:54 +05301860 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001861 if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret)
Vivek Natarajan94db2932009-11-25 12:01:54 +05301862 ath_beaconq_config(sc);
1863
Sujith141b38b2009-02-04 08:10:07 +05301864 mutex_unlock(&sc->mutex);
1865
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001866 return ret;
1867}
1868
1869static int ath9k_set_key(struct ieee80211_hw *hw,
1870 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001871 struct ieee80211_vif *vif,
1872 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873 struct ieee80211_key_conf *key)
1874{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001875 struct ath_wiphy *aphy = hw->priv;
1876 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001877 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001878 int ret = 0;
1879
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001880 if (modparam_nohwcrypt)
1881 return -ENOSPC;
1882
Sujith141b38b2009-02-04 08:10:07 +05301883 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301884 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001885 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001886
1887 switch (cmd) {
1888 case SET_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001889 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001890 if (ret >= 0) {
1891 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001892 /* push IV and Michael MIC generation to stack */
1893 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Johannes Berg97359d12010-08-10 09:46:38 +02001894 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301895 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg97359d12010-08-10 09:46:38 +02001896 if (sc->sc_ah->sw_mgmt_crypto &&
1897 key->cipher == WLAN_CIPHER_SUITE_CCMP)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001898 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001899 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001900 }
1901 break;
1902 case DISABLE_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001903 ath_key_delete(common, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001904 break;
1905 default:
1906 ret = -EINVAL;
1907 }
1908
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301909 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301910 mutex_unlock(&sc->mutex);
1911
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001912 return ret;
1913}
1914
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001915static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1916 struct ieee80211_vif *vif,
1917 struct ieee80211_bss_conf *bss_conf,
1918 u32 changed)
1919{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001920 struct ath_wiphy *aphy = hw->priv;
1921 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001922 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001923 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001924 struct ath_vif *avp = (void *)vif->drv_priv;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001925 int slottime;
Sujithc6089cc2009-11-16 11:40:48 +05301926 int error;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001927
Sujith141b38b2009-02-04 08:10:07 +05301928 mutex_lock(&sc->mutex);
1929
Sujithc6089cc2009-11-16 11:40:48 +05301930 if (changed & BSS_CHANGED_BSSID) {
1931 /* Set BSSID */
1932 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1933 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001934 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001935 ath9k_hw_write_associd(ah);
Sujithc6089cc2009-11-16 11:40:48 +05301936
1937 /* Set aggregation protection mode parameters */
1938 sc->config.ath_aggr_prot = 0;
1939
1940 /* Only legacy IBSS for now */
1941 if (vif->type == NL80211_IFTYPE_ADHOC)
1942 ath_update_chainmask(sc, 0);
1943
1944 ath_print(common, ATH_DBG_CONFIG,
1945 "BSSID: %pM aid: 0x%x\n",
1946 common->curbssid, common->curaid);
1947
1948 /* need to reconfigure the beacon */
1949 sc->sc_flags &= ~SC_OP_BEACONS ;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001950 }
1951
Sujithc6089cc2009-11-16 11:40:48 +05301952 /* Enable transmission of beacons (AP, IBSS, MESH) */
1953 if ((changed & BSS_CHANGED_BEACON) ||
1954 ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
1955 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1956 error = ath_beacon_alloc(aphy, vif);
1957 if (!error)
1958 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001959 }
1960
Felix Fietkau0005baf2010-01-15 02:33:40 +01001961 if (changed & BSS_CHANGED_ERP_SLOT) {
1962 if (bss_conf->use_short_slot)
1963 slottime = 9;
1964 else
1965 slottime = 20;
1966 if (vif->type == NL80211_IFTYPE_AP) {
1967 /*
1968 * Defer update, so that connected stations can adjust
1969 * their settings at the same time.
1970 * See beacon.c for more details
1971 */
1972 sc->beacon.slottime = slottime;
1973 sc->beacon.updateslot = UPDATE;
1974 } else {
1975 ah->slottime = slottime;
1976 ath9k_hw_init_global_settings(ah);
1977 }
1978 }
1979
Sujithc6089cc2009-11-16 11:40:48 +05301980 /* Disable transmission of beacons */
1981 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
1982 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1983
1984 if (changed & BSS_CHANGED_BEACON_INT) {
1985 sc->beacon_interval = bss_conf->beacon_int;
1986 /*
1987 * In case of AP mode, the HW TSF has to be reset
1988 * when the beacon interval changes.
1989 */
1990 if (vif->type == NL80211_IFTYPE_AP) {
1991 sc->sc_flags |= SC_OP_TSF_RESET;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001992 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001993 error = ath_beacon_alloc(aphy, vif);
1994 if (!error)
1995 ath_beacon_config(sc, vif);
Sujithc6089cc2009-11-16 11:40:48 +05301996 } else {
1997 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001998 }
1999 }
2000
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002001 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002002 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
2003 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002004 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302005 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002006 else
Sujith672840a2008-08-11 14:05:08 +05302007 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002008 }
2009
2010 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002011 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
2012 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002013 if (bss_conf->use_cts_prot &&
2014 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302015 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002016 else
Sujith672840a2008-08-11 14:05:08 +05302017 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002018 }
2019
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002020 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002021 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002022 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302023 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002024 }
Sujith141b38b2009-02-04 08:10:07 +05302025
2026 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002027}
2028
2029static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2030{
2031 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002032 struct ath_wiphy *aphy = hw->priv;
2033 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002034
Sujith141b38b2009-02-04 08:10:07 +05302035 mutex_lock(&sc->mutex);
2036 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2037 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038
2039 return tsf;
2040}
2041
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002042static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2043{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002044 struct ath_wiphy *aphy = hw->priv;
2045 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002046
Sujith141b38b2009-02-04 08:10:07 +05302047 mutex_lock(&sc->mutex);
2048 ath9k_hw_settsf64(sc->sc_ah, tsf);
2049 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002050}
2051
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002052static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2053{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002054 struct ath_wiphy *aphy = hw->priv;
2055 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002056
Sujith141b38b2009-02-04 08:10:07 +05302057 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002058
2059 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05302060 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002061 ath9k_ps_restore(sc);
2062
Sujith141b38b2009-02-04 08:10:07 +05302063 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002064}
2065
2066static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01002067 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05302068 enum ieee80211_ampdu_mlme_action action,
2069 struct ieee80211_sta *sta,
2070 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002072 struct ath_wiphy *aphy = hw->priv;
2073 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002074 int ret = 0;
2075
Johannes Berg85ad1812010-06-10 10:21:49 +02002076 local_bh_disable();
2077
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002078 switch (action) {
2079 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05302080 if (!(sc->sc_flags & SC_OP_RXAGGR))
2081 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002082 break;
2083 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002084 break;
2085 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002086 ath9k_ps_wakeup(sc);
Felix Fietkau231c3a12010-09-20 19:35:28 +02002087 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
2088 if (!ret)
2089 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002090 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002091 break;
2092 case IEEE80211_AMPDU_TX_STOP:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002093 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05302094 ath_tx_aggr_stop(sc, sta, tid);
Johannes Bergc951ad32009-11-16 12:00:38 +01002095 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002096 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002097 break;
Johannes Bergb1720232009-03-23 17:28:39 +01002098 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002099 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05302100 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002101 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05302102 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002103 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002104 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
2105 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002106 }
2107
Johannes Berg85ad1812010-06-10 10:21:49 +02002108 local_bh_enable();
2109
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002110 return ret;
2111}
2112
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002113static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
2114 struct survey_info *survey)
2115{
2116 struct ath_wiphy *aphy = hw->priv;
2117 struct ath_softc *sc = aphy->sc;
Felix Fietkau34300982010-10-10 18:21:52 +02002118 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39162db2010-09-29 19:12:06 +02002119 struct ieee80211_supported_band *sband;
Felix Fietkau34300982010-10-10 18:21:52 +02002120 struct ieee80211_channel *chan;
2121 unsigned long flags;
2122 int pos;
2123
2124 spin_lock_irqsave(&common->cc_lock, flags);
2125 if (idx == 0)
2126 ath_update_survey_stats(sc);
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002127
Felix Fietkau39162db2010-09-29 19:12:06 +02002128 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2129 if (sband && idx >= sband->n_channels) {
2130 idx -= sband->n_channels;
2131 sband = NULL;
2132 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002133
Felix Fietkau39162db2010-09-29 19:12:06 +02002134 if (!sband)
2135 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2136
Felix Fietkau34300982010-10-10 18:21:52 +02002137 if (!sband || idx >= sband->n_channels) {
2138 spin_unlock_irqrestore(&common->cc_lock, flags);
2139 return -ENOENT;
Felix Fietkau4f1a5a42010-09-29 17:15:28 +02002140 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002141
Felix Fietkau34300982010-10-10 18:21:52 +02002142 chan = &sband->channels[idx];
2143 pos = chan->hw_value;
2144 memcpy(survey, &sc->survey[pos], sizeof(*survey));
2145 survey->channel = chan;
2146 spin_unlock_irqrestore(&common->cc_lock, flags);
2147
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002148 return 0;
2149}
2150
Sujith0c98de62009-03-03 10:16:45 +05302151static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2152{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002153 struct ath_wiphy *aphy = hw->priv;
2154 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302155
Sujith3d832612009-08-21 12:00:28 +05302156 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002157 if (ath9k_wiphy_scanning(sc)) {
Jouni Malinen8089cc42009-03-03 19:23:38 +02002158 /*
Luis R. Rodriguez30888332010-07-27 16:33:06 -04002159 * There is a race here in mac80211 but fixing it requires
2160 * we revisit how we handle the scan complete callback.
2161 * After mac80211 fixes we will not have configured hardware
2162 * to the home channel nor would we have configured the RX
2163 * filter yet.
Jouni Malinen8089cc42009-03-03 19:23:38 +02002164 */
Sujith3d832612009-08-21 12:00:28 +05302165 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002166 return;
2167 }
2168
2169 aphy->state = ATH_WIPHY_SCAN;
2170 ath9k_wiphy_pause_all_forced(sc, aphy);
Sujith3d832612009-08-21 12:00:28 +05302171 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302172}
2173
Luis R. Rodriguez30888332010-07-27 16:33:06 -04002174/*
2175 * XXX: this requires a revisit after the driver
2176 * scan_complete gets moved to another place/removed in mac80211.
2177 */
Sujith0c98de62009-03-03 10:16:45 +05302178static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2179{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002180 struct ath_wiphy *aphy = hw->priv;
2181 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302182
Sujith3d832612009-08-21 12:00:28 +05302183 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002184 aphy->state = ATH_WIPHY_ACTIVE;
Sujith3d832612009-08-21 12:00:28 +05302185 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302186}
2187
Felix Fietkaue239d852010-01-15 02:34:58 +01002188static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
2189{
2190 struct ath_wiphy *aphy = hw->priv;
2191 struct ath_softc *sc = aphy->sc;
2192 struct ath_hw *ah = sc->sc_ah;
2193
2194 mutex_lock(&sc->mutex);
2195 ah->coverage_class = coverage_class;
2196 ath9k_hw_init_global_settings(ah);
2197 mutex_unlock(&sc->mutex);
2198}
2199
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002200struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002201 .tx = ath9k_tx,
2202 .start = ath9k_start,
2203 .stop = ath9k_stop,
2204 .add_interface = ath9k_add_interface,
2205 .remove_interface = ath9k_remove_interface,
2206 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002207 .configure_filter = ath9k_configure_filter,
Johannes Berg4ca77862010-02-19 19:06:56 +01002208 .sta_add = ath9k_sta_add,
2209 .sta_remove = ath9k_sta_remove,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002210 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002211 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002212 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002213 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002214 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002216 .ampdu_action = ath9k_ampdu_action,
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002217 .get_survey = ath9k_get_survey,
Sujith0c98de62009-03-03 10:16:45 +05302218 .sw_scan_start = ath9k_sw_scan_start,
2219 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302220 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002221 .set_coverage_class = ath9k_set_coverage_class,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222};