blob: 09dcdd7882e6830ff8723832341e2755ecd7f08f [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>
Vivek Natarajan10598c12010-10-30 22:05:13 +053018#include <linux/pm_qos_params.h>
Sujith394cf0a2009-02-09 13:26:54 +053019#include "ath9k.h"
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070020#include "btcoex.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021
Sujithff37e332008-11-24 12:07:55 +053022static void ath_update_txpow(struct ath_softc *sc)
23{
Sujithcbe61d8a2009-02-09 13:27:12 +053024 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +053025
Sujith17d79042009-02-09 13:27:03 +053026 if (sc->curtxpow != sc->config.txpowlimit) {
27 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +053028 /* read back in case value is clamped */
Felix Fietkau9cc32712010-06-12 17:22:29 +020029 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
Sujithff37e332008-11-24 12:07:55 +053030 }
31}
32
33static u8 parse_mpdudensity(u8 mpdudensity)
34{
35 /*
36 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
37 * 0 for no restriction
38 * 1 for 1/4 us
39 * 2 for 1/2 us
40 * 3 for 1 us
41 * 4 for 2 us
42 * 5 for 4 us
43 * 6 for 8 us
44 * 7 for 16 us
45 */
46 switch (mpdudensity) {
47 case 0:
48 return 0;
49 case 1:
50 case 2:
51 case 3:
52 /* Our lower layer calculations limit our precision to
53 1 microsecond */
54 return 1;
55 case 4:
56 return 2;
57 case 5:
58 return 4;
59 case 6:
60 return 8;
61 case 7:
62 return 16;
63 default:
64 return 0;
65 }
66}
67
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +053068static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
69 struct ieee80211_hw *hw)
70{
71 struct ieee80211_channel *curchan = hw->conf.channel;
72 struct ath9k_channel *channel;
73 u8 chan_idx;
74
75 chan_idx = curchan->hw_value;
76 channel = &sc->sc_ah->channels[chan_idx];
77 ath9k_update_ichannel(sc, hw, channel);
78 return channel;
79}
80
Sujith55624202010-01-08 10:36:02 +053081bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070082{
83 unsigned long flags;
84 bool ret;
85
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -070086 spin_lock_irqsave(&sc->sc_pm_lock, flags);
87 ret = ath9k_hw_setpower(sc->sc_ah, mode);
88 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -070089
90 return ret;
91}
92
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070093void ath9k_ps_wakeup(struct ath_softc *sc)
94{
Felix Fietkau898c9142010-10-12 14:02:53 +020095 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -070096 unsigned long flags;
97
98 spin_lock_irqsave(&sc->sc_pm_lock, flags);
99 if (++sc->ps_usecount != 1)
100 goto unlock;
101
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700102 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700103
Felix Fietkau898c9142010-10-12 14:02:53 +0200104 /*
105 * While the hardware is asleep, the cycle counters contain no
106 * useful data. Better clear them now so that they don't mess up
107 * survey data results.
108 */
109 spin_lock(&common->cc_lock);
110 ath_hw_cycle_counters_update(common);
111 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
112 spin_unlock(&common->cc_lock);
113
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700114 unlock:
115 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
116}
117
118void ath9k_ps_restore(struct ath_softc *sc)
119{
Felix Fietkau898c9142010-10-12 14:02:53 +0200120 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700121 unsigned long flags;
122
123 spin_lock_irqsave(&sc->sc_pm_lock, flags);
124 if (--sc->ps_usecount != 0)
125 goto unlock;
126
Felix Fietkau898c9142010-10-12 14:02:53 +0200127 spin_lock(&common->cc_lock);
128 ath_hw_cycle_counters_update(common);
129 spin_unlock(&common->cc_lock);
130
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +0530131 if (sc->ps_idle)
132 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
133 else if (sc->ps_enabled &&
134 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
Sujith1b04b932010-01-08 10:36:05 +0530135 PS_WAIT_FOR_CAB |
136 PS_WAIT_FOR_PSPOLL_DATA |
137 PS_WAIT_FOR_TX_ACK)))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700138 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700139
140 unlock:
141 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
142}
143
Felix Fietkau5ee08652010-07-31 00:11:59 +0200144static void ath_start_ani(struct ath_common *common)
145{
146 struct ath_hw *ah = common->ah;
147 unsigned long timestamp = jiffies_to_msecs(jiffies);
148 struct ath_softc *sc = (struct ath_softc *) common->priv;
149
150 if (!(sc->sc_flags & SC_OP_ANI_RUN))
151 return;
152
153 if (sc->sc_flags & SC_OP_OFFCHANNEL)
154 return;
155
156 common->ani.longcal_timer = timestamp;
157 common->ani.shortcal_timer = timestamp;
158 common->ani.checkani_timer = timestamp;
159
160 mod_timer(&common->ani.timer,
161 jiffies +
162 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
163}
164
Felix Fietkau34300982010-10-10 18:21:52 +0200165static void ath_update_survey_nf(struct ath_softc *sc, int channel)
166{
167 struct ath_hw *ah = sc->sc_ah;
168 struct ath9k_channel *chan = &ah->channels[channel];
169 struct survey_info *survey = &sc->survey[channel];
170
171 if (chan->noisefloor) {
172 survey->filled |= SURVEY_INFO_NOISE_DBM;
173 survey->noise = chan->noisefloor;
174 }
175}
176
177static void ath_update_survey_stats(struct ath_softc *sc)
178{
179 struct ath_hw *ah = sc->sc_ah;
180 struct ath_common *common = ath9k_hw_common(ah);
181 int pos = ah->curchan - &ah->channels[0];
182 struct survey_info *survey = &sc->survey[pos];
183 struct ath_cycle_counters *cc = &common->cc_survey;
184 unsigned int div = common->clockrate * 1000;
185
Felix Fietkau08457352010-10-20 15:59:28 +0200186 if (!ah->curchan)
187 return;
188
Felix Fietkau898c9142010-10-12 14:02:53 +0200189 if (ah->power_mode == ATH9K_PM_AWAKE)
190 ath_hw_cycle_counters_update(common);
Felix Fietkau34300982010-10-10 18:21:52 +0200191
192 if (cc->cycles > 0) {
193 survey->filled |= SURVEY_INFO_CHANNEL_TIME |
194 SURVEY_INFO_CHANNEL_TIME_BUSY |
195 SURVEY_INFO_CHANNEL_TIME_RX |
196 SURVEY_INFO_CHANNEL_TIME_TX;
197 survey->channel_time += cc->cycles / div;
198 survey->channel_time_busy += cc->rx_busy / div;
199 survey->channel_time_rx += cc->rx_frame / div;
200 survey->channel_time_tx += cc->tx_frame / div;
201 }
202 memset(cc, 0, sizeof(*cc));
203
204 ath_update_survey_nf(sc, pos);
205}
206
Sujithff37e332008-11-24 12:07:55 +0530207/*
208 * Set/change channels. If the channel is really being changed, it's done
209 * by reseting the chip. To accomplish this we must first cleanup any pending
210 * DMA, then restart stuff.
211*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200212int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
213 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530214{
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200215 struct ath_wiphy *aphy = hw->priv;
Sujithcbe61d8a2009-02-09 13:27:12 +0530216 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700217 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700218 struct ieee80211_conf *conf = &common->hw->conf;
Sujithff37e332008-11-24 12:07:55 +0530219 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800220 struct ieee80211_channel *channel = hw->conf.channel;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200221 struct ath9k_hw_cal_data *caldata = NULL;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800222 int r;
Sujithff37e332008-11-24 12:07:55 +0530223
224 if (sc->sc_flags & SC_OP_INVALID)
225 return -EIO;
226
Felix Fietkau5ee08652010-07-31 00:11:59 +0200227 del_timer_sync(&common->ani.timer);
228 cancel_work_sync(&sc->paprd_work);
229 cancel_work_sync(&sc->hw_check_work);
230 cancel_delayed_work_sync(&sc->tx_complete_work);
231
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530232 ath9k_ps_wakeup(sc);
233
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800234 /*
235 * This is only performed if the channel settings have
236 * actually changed.
237 *
238 * To switch channels clear any pending DMA operations;
239 * wait long enough for the RX fifo to drain, reset the
240 * hardware at the new frequency, and then re-enable
241 * the relevant bits of the h/w.
242 */
243 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530244 ath_drain_all_txq(sc, false);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700245
246 spin_lock_bh(&sc->rx.pcu_lock);
247
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800248 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530249
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800250 /* XXX: do not flush receive queue here. We don't want
251 * to flush data frames already in queue because of
252 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530253
Felix Fietkau5ee08652010-07-31 00:11:59 +0200254 if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800255 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530256
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200257 if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
258 caldata = &aphy->caldata;
259
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700260 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguez1e51b2f2010-07-29 22:56:22 -0400261 "(%u MHz) -> (%u MHz), conf_is_ht40: %d fastcc: %d\n",
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700262 sc->sc_ah->curchan->channel,
Luis R. Rodriguez1e51b2f2010-07-29 22:56:22 -0400263 channel->center_freq, conf_is_ht40(conf),
264 fastcc);
Sujith99405f92008-11-24 12:08:35 +0530265
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800266 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800267
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200268 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800269 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700270 ath_print(common, ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500271 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700272 "reset status %d\n",
273 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530274 spin_unlock_bh(&sc->sc_resetlock);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700275 spin_unlock_bh(&sc->rx.pcu_lock);
Gabor Juhos39892792009-06-15 17:49:09 +0200276 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530277 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800278 spin_unlock_bh(&sc->sc_resetlock);
279
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800280 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700281 ath_print(common, ATH_DBG_FATAL,
282 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200283 r = -EIO;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700284 spin_unlock_bh(&sc->rx.pcu_lock);
Gabor Juhos39892792009-06-15 17:49:09 +0200285 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800286 }
287
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700288 spin_unlock_bh(&sc->rx.pcu_lock);
289
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800290 ath_update_txpow(sc);
Pavel Roskin30691682010-03-31 18:05:31 -0400291 ath9k_hw_set_interrupts(ah, ah->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200292
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400293 if (!(sc->sc_flags & (SC_OP_OFFCHANNEL))) {
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -0400294 ath_beacon_config(sc, NULL);
Luis R. Rodriguez48a6a462010-09-16 15:12:28 -0400295 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
296 ath_start_ani(common);
297 }
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -0400298
Gabor Juhos39892792009-06-15 17:49:09 +0200299 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530300 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200301 return r;
Sujithff37e332008-11-24 12:07:55 +0530302}
303
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400304static void ath_paprd_activate(struct ath_softc *sc)
305{
306 struct ath_hw *ah = sc->sc_ah;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200307 struct ath9k_hw_cal_data *caldata = ah->caldata;
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700308 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400309 int chain;
310
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200311 if (!caldata || !caldata->paprd_done)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400312 return;
313
314 ath9k_ps_wakeup(sc);
Felix Fietkauddfef792010-07-30 21:02:11 +0200315 ar9003_paprd_enable(ah, false);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400316 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700317 if (!(common->tx_chainmask & BIT(chain)))
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400318 continue;
319
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200320 ar9003_paprd_populate_single_table(ah, caldata, chain);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400321 }
322
323 ar9003_paprd_enable(ah, true);
324 ath9k_ps_restore(sc);
325}
326
327void ath_paprd_calibrate(struct work_struct *work)
328{
329 struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
330 struct ieee80211_hw *hw = sc->hw;
331 struct ath_hw *ah = sc->sc_ah;
332 struct ieee80211_hdr *hdr;
333 struct sk_buff *skb = NULL;
334 struct ieee80211_tx_info *tx_info;
335 int band = hw->conf.channel->band;
336 struct ieee80211_supported_band *sband = &sc->sbands[band];
337 struct ath_tx_control txctl;
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200338 struct ath9k_hw_cal_data *caldata = ah->caldata;
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700339 struct ath_common *common = ath9k_hw_common(ah);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400340 int qnum, ftype;
341 int chain_ok = 0;
342 int chain;
343 int len = 1800;
344 int time_left;
345 int i;
346
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200347 if (!caldata)
348 return;
349
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400350 skb = alloc_skb(len, GFP_KERNEL);
351 if (!skb)
352 return;
353
354 tx_info = IEEE80211_SKB_CB(skb);
355
356 skb_put(skb, len);
357 memset(skb->data, 0, len);
358 hdr = (struct ieee80211_hdr *)skb->data;
359 ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
360 hdr->frame_control = cpu_to_le16(ftype);
John W. Linvillea3d3da12010-07-20 13:15:31 -0400361 hdr->duration_id = cpu_to_le16(10);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400362 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
363 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
364 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
365
366 memset(&txctl, 0, sizeof(txctl));
367 qnum = sc->tx.hwq_map[WME_AC_BE];
368 txctl.txq = &sc->tx.txq[qnum];
369
Vasanthakumar Thiagarajan47399f12010-06-24 04:09:27 -0700370 ath9k_ps_wakeup(sc);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400371 ar9003_paprd_init_table(ah);
372 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
Vasanthakumar Thiagarajan90945372010-09-20 22:54:46 -0700373 if (!(common->tx_chainmask & BIT(chain)))
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400374 continue;
375
376 chain_ok = 0;
377 memset(tx_info, 0, sizeof(*tx_info));
378 tx_info->band = band;
379
380 for (i = 0; i < 4; i++) {
381 tx_info->control.rates[i].idx = sband->n_bitrates - 1;
382 tx_info->control.rates[i].count = 6;
383 }
384
385 init_completion(&sc->paprd_complete);
386 ar9003_paprd_setup_gain_table(ah, chain);
387 txctl.paprd = BIT(chain);
388 if (ath_tx_start(hw, skb, &txctl) != 0)
389 break;
390
391 time_left = wait_for_completion_timeout(&sc->paprd_complete,
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700392 msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400393 if (!time_left) {
394 ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
395 "Timeout waiting for paprd training on "
396 "TX chain %d\n",
397 chain);
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700398 goto fail_paprd;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400399 }
400
401 if (!ar9003_paprd_is_done(ah))
402 break;
403
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200404 if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400405 break;
406
407 chain_ok = 1;
408 }
409 kfree_skb(skb);
410
411 if (chain_ok) {
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200412 caldata->paprd_done = true;
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400413 ath_paprd_activate(sc);
414 }
415
Vasanthakumar Thiagarajanca369eb2010-06-24 02:42:44 -0700416fail_paprd:
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400417 ath9k_ps_restore(sc);
418}
419
Sujithff37e332008-11-24 12:07:55 +0530420/*
421 * This routine performs the periodic noise floor calibration function
422 * that is used to adjust and optimize the chip performance. This
423 * takes environmental changes (location, temperature) into account.
424 * When the task is complete, it reschedules itself depending on the
425 * appropriate interval that was calculated.
426 */
Sujith55624202010-01-08 10:36:02 +0530427void ath_ani_calibrate(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530428{
Sujith20977d32009-02-20 15:13:28 +0530429 struct ath_softc *sc = (struct ath_softc *)data;
430 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700431 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530432 bool longcal = false;
433 bool shortcal = false;
434 bool aniflag = false;
435 unsigned int timestamp = jiffies_to_msecs(jiffies);
Felix Fietkau60444742010-08-02 15:53:15 +0200436 u32 cal_interval, short_cal_interval, long_cal_interval;
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200437 unsigned long flags;
Felix Fietkau60444742010-08-02 15:53:15 +0200438
439 if (ah->caldata && ah->caldata->nfcal_interference)
440 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
441 else
442 long_cal_interval = ATH_LONG_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530443
Sujith20977d32009-02-20 15:13:28 +0530444 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
445 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530446
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300447 /* Only calibrate if awake */
448 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
449 goto set_timer;
450
451 ath9k_ps_wakeup(sc);
452
Sujithff37e332008-11-24 12:07:55 +0530453 /* Long calibration runs independently of short calibration. */
Felix Fietkau60444742010-08-02 15:53:15 +0200454 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530455 longcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700456 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800457 common->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530458 }
459
Sujith17d79042009-02-09 13:27:03 +0530460 /* Short calibration applies only while caldone is false */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800461 if (!common->ani.caldone) {
462 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530463 shortcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700464 ath_print(common, ATH_DBG_ANI,
465 "shortcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800466 common->ani.shortcal_timer = timestamp;
467 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530468 }
469 } else {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800470 if ((timestamp - common->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530471 ATH_RESTART_CALINTERVAL) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800472 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
473 if (common->ani.caldone)
474 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530475 }
476 }
477
478 /* Verify whether we must check ANI */
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400479 if ((timestamp - common->ani.checkani_timer) >=
480 ah->config.ani_poll_interval) {
Sujithff37e332008-11-24 12:07:55 +0530481 aniflag = true;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800482 common->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530483 }
484
485 /* Skip all processing if there's nothing to do. */
486 if (longcal || shortcal || aniflag) {
487 /* Call ANI routine if necessary */
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200488 if (aniflag) {
489 spin_lock_irqsave(&common->cc_lock, flags);
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530490 ath9k_hw_ani_monitor(ah, ah->curchan);
Felix Fietkau34300982010-10-10 18:21:52 +0200491 ath_update_survey_stats(sc);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200492 spin_unlock_irqrestore(&common->cc_lock, flags);
493 }
Sujithff37e332008-11-24 12:07:55 +0530494
495 /* Perform calibration if necessary */
496 if (longcal || shortcal) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800497 common->ani.caldone =
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700498 ath9k_hw_calibrate(ah,
499 ah->curchan,
500 common->rx_chainmask,
501 longcal);
Sujithff37e332008-11-24 12:07:55 +0530502 }
503 }
504
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300505 ath9k_ps_restore(sc);
506
Sujith20977d32009-02-20 15:13:28 +0530507set_timer:
Sujithff37e332008-11-24 12:07:55 +0530508 /*
509 * Set timer interval based on previous results.
510 * The interval must be the shortest necessary to satisfy ANI,
511 * short calibration and long calibration.
512 */
Sujithaac92072008-12-02 18:37:54 +0530513 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530514 if (sc->sc_ah->config.enable_ani)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400515 cal_interval = min(cal_interval,
516 (u32)ah->config.ani_poll_interval);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800517 if (!common->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530518 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530519
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800520 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200521 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
522 if (!ah->caldata->paprd_done)
Felix Fietkau9f42c2b2010-06-12 00:34:01 -0400523 ieee80211_queue_work(sc->hw, &sc->paprd_work);
524 else
525 ath_paprd_activate(sc);
526 }
Sujithff37e332008-11-24 12:07:55 +0530527}
528
529/*
530 * Update tx/rx chainmask. For legacy association,
531 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530532 * the chainmask configuration, for bt coexistence, use
533 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530534 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200535void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530536{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700537 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700538 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700539
Felix Fietkau5ee08652010-07-31 00:11:59 +0200540 if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700541 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700542 common->tx_chainmask = ah->caps.tx_chainmask;
543 common->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530544 } else {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700545 common->tx_chainmask = 1;
546 common->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530547 }
548
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700549 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700550 "tx chmask: %d, rx chmask: %d\n",
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700551 common->tx_chainmask,
552 common->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530553}
554
555static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
556{
557 struct ath_node *an;
558
559 an = (struct ath_node *)sta->drv_priv;
560
Sujith87792ef2009-03-30 15:28:48 +0530561 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530562 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530563 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530564 sta->ht_cap.ampdu_factor);
565 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400566 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530567 }
Sujithff37e332008-11-24 12:07:55 +0530568}
569
570static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
571{
572 struct ath_node *an = (struct ath_node *)sta->drv_priv;
573
574 if (sc->sc_flags & SC_OP_TXAGGR)
575 ath_tx_node_cleanup(sc, an);
576}
577
Felix Fietkau347809f2010-07-02 00:09:52 +0200578void ath_hw_check(struct work_struct *work)
579{
580 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
581 int i;
582
583 ath9k_ps_wakeup(sc);
584
585 for (i = 0; i < 3; i++) {
586 if (ath9k_hw_check_alive(sc->sc_ah))
587 goto out;
588
589 msleep(1);
590 }
Felix Fietkaufac6b6a2010-10-23 17:45:38 +0200591 ath_reset(sc, true);
Felix Fietkau347809f2010-07-02 00:09:52 +0200592
593out:
594 ath9k_ps_restore(sc);
595}
596
Sujith55624202010-01-08 10:36:02 +0530597void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530598{
599 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700600 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700601 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700602
Sujith17d79042009-02-09 13:27:03 +0530603 u32 status = sc->intrstatus;
Felix Fietkaub5c804752010-04-15 17:38:48 -0400604 u32 rxmask;
Sujithff37e332008-11-24 12:07:55 +0530605
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400606 ath9k_ps_wakeup(sc);
607
Felix Fietkau347809f2010-07-02 00:09:52 +0200608 if (status & ATH9K_INT_FATAL) {
Felix Fietkaufac6b6a2010-10-23 17:45:38 +0200609 ath_reset(sc, true);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400610 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530611 return;
Sujithff37e332008-11-24 12:07:55 +0530612 }
613
Felix Fietkau347809f2010-07-02 00:09:52 +0200614 if (!ath9k_hw_check_alive(ah))
615 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
616
Felix Fietkaub5c804752010-04-15 17:38:48 -0400617 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
618 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
619 ATH9K_INT_RXORN);
620 else
621 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
622
623 if (status & rxmask) {
Luis R. Rodriguezb79b33c2010-10-20 16:07:05 -0700624 spin_lock_bh(&sc->rx.pcu_lock);
Felix Fietkaub5c804752010-04-15 17:38:48 -0400625
626 /* Check for high priority Rx first */
627 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
628 (status & ATH9K_INT_RXHP))
629 ath_rx_tasklet(sc, 0, true);
630
631 ath_rx_tasklet(sc, 0, false);
Luis R. Rodriguezb79b33c2010-10-20 16:07:05 -0700632 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith063d8be2009-03-30 15:28:49 +0530633 }
634
Vasanthakumar Thiagarajane5003242010-04-15 17:39:36 -0400635 if (status & ATH9K_INT_TX) {
636 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
637 ath_tx_edma_tasklet(sc);
638 else
639 ath_tx_tasklet(sc);
640 }
Sujith063d8be2009-03-30 15:28:49 +0530641
Gabor Juhos96148322009-07-24 17:27:21 +0200642 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300643 /*
644 * TSF sync does not look correct; remain awake to sync with
645 * the next Beacon.
646 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700647 ath_print(common, ATH_DBG_PS,
648 "TSFOOR - Sync with next Beacon\n");
Sujith1b04b932010-01-08 10:36:05 +0530649 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300650 }
651
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700652 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530653 if (status & ATH9K_INT_GENTIMER)
654 ath_gen_timer_isr(sc->sc_ah);
655
Sujithff37e332008-11-24 12:07:55 +0530656 /* re-enable hardware interrupt */
Pavel Roskin30691682010-03-31 18:05:31 -0400657 ath9k_hw_set_interrupts(ah, ah->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400658 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530659}
660
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100661irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530662{
Sujith063d8be2009-03-30 15:28:49 +0530663#define SCHED_INTR ( \
664 ATH9K_INT_FATAL | \
665 ATH9K_INT_RXORN | \
666 ATH9K_INT_RXEOL | \
667 ATH9K_INT_RX | \
Felix Fietkaub5c804752010-04-15 17:38:48 -0400668 ATH9K_INT_RXLP | \
669 ATH9K_INT_RXHP | \
Sujith063d8be2009-03-30 15:28:49 +0530670 ATH9K_INT_TX | \
671 ATH9K_INT_BMISS | \
672 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530673 ATH9K_INT_TSFOOR | \
674 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530675
Sujithff37e332008-11-24 12:07:55 +0530676 struct ath_softc *sc = dev;
Sujithcbe61d8a2009-02-09 13:27:12 +0530677 struct ath_hw *ah = sc->sc_ah;
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200678 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530679 enum ath9k_int status;
680 bool sched = false;
681
Sujith063d8be2009-03-30 15:28:49 +0530682 /*
683 * The hardware is not ready/present, don't
684 * touch anything. Note this can happen early
685 * on if the IRQ is shared.
686 */
687 if (sc->sc_flags & SC_OP_INVALID)
688 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530689
Sujithff37e332008-11-24 12:07:55 +0530690
Sujith063d8be2009-03-30 15:28:49 +0530691 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530692
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400693 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530694 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530695
Sujith063d8be2009-03-30 15:28:49 +0530696 /*
697 * Figure out the reason(s) for the interrupt. Note
698 * that the hal returns a pseudo-ISR that may include
699 * bits we haven't explicitly enabled so we mask the
700 * value to insure we only process bits we requested.
701 */
702 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
Pavel Roskin30691682010-03-31 18:05:31 -0400703 status &= ah->imask; /* discard unasked-for bits */
Sujith063d8be2009-03-30 15:28:49 +0530704
705 /*
706 * If there are no status bits set, then this interrupt was not
707 * for me (should have been caught above).
708 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400709 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530710 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530711
712 /* Cache the status */
713 sc->intrstatus = status;
714
715 if (status & SCHED_INTR)
716 sched = true;
717
718 /*
719 * If a FATAL or RXORN interrupt is received, we have to reset the
720 * chip immediately.
721 */
Felix Fietkaub5c804752010-04-15 17:38:48 -0400722 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
723 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
Sujith063d8be2009-03-30 15:28:49 +0530724 goto chip_reset;
725
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400726 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
727 (status & ATH9K_INT_BB_WATCHDOG)) {
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200728
729 spin_lock(&common->cc_lock);
730 ath_hw_cycle_counters_update(common);
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400731 ar9003_hw_bb_watchdog_dbg_info(ah);
Felix Fietkaub5bfc562010-10-08 22:13:53 +0200732 spin_unlock(&common->cc_lock);
733
Luis R. Rodriguez08578b82010-05-13 13:33:44 -0400734 goto chip_reset;
735 }
736
Sujith063d8be2009-03-30 15:28:49 +0530737 if (status & ATH9K_INT_SWBA)
738 tasklet_schedule(&sc->bcon_tasklet);
739
740 if (status & ATH9K_INT_TXURN)
741 ath9k_hw_updatetxtriglevel(ah, true);
742
Felix Fietkaub5c804752010-04-15 17:38:48 -0400743 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
744 if (status & ATH9K_INT_RXEOL) {
745 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
746 ath9k_hw_set_interrupts(ah, ah->imask);
747 }
748 }
749
Sujith063d8be2009-03-30 15:28:49 +0530750 if (status & ATH9K_INT_MIB) {
751 /*
752 * Disable interrupts until we service the MIB
753 * interrupt; otherwise it will continue to
754 * fire.
755 */
756 ath9k_hw_set_interrupts(ah, 0);
757 /*
758 * Let the hal handle the event. We assume
759 * it will clear whatever condition caused
760 * the interrupt.
761 */
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200762 spin_lock(&common->cc_lock);
Felix Fietkaubfc472b2010-10-04 20:09:48 +0200763 ath9k_hw_proc_mib_event(ah);
Felix Fietkau88eac2d2010-10-12 16:08:03 +0200764 spin_unlock(&common->cc_lock);
Pavel Roskin30691682010-03-31 18:05:31 -0400765 ath9k_hw_set_interrupts(ah, ah->imask);
Sujith063d8be2009-03-30 15:28:49 +0530766 }
767
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400768 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
769 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530770 /* Clear RxAbort bit so that we can
771 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700772 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400773 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530774 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith063d8be2009-03-30 15:28:49 +0530775 }
Sujith063d8be2009-03-30 15:28:49 +0530776
777chip_reset:
778
Sujith817e11d2008-12-07 21:42:44 +0530779 ath_debug_stat_interrupt(sc, status);
780
Sujithff37e332008-11-24 12:07:55 +0530781 if (sched) {
782 /* turn off every interrupt except SWBA */
Pavel Roskin30691682010-03-31 18:05:31 -0400783 ath9k_hw_set_interrupts(ah, (ah->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530784 tasklet_schedule(&sc->intr_tq);
785 }
786
787 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530788
789#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530790}
791
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700792static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530793 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530794 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700795{
796 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797
798 switch (chan->band) {
799 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530800 switch(channel_type) {
801 case NL80211_CHAN_NO_HT:
802 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530804 break;
805 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700806 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530807 break;
808 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530810 break;
811 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700812 break;
813 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530814 switch(channel_type) {
815 case NL80211_CHAN_NO_HT:
816 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700817 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530818 break;
819 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700820 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530821 break;
822 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700823 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530824 break;
825 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700826 break;
827 default:
828 break;
829 }
830
831 return chanmode;
832}
833
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530834static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530835 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530836 struct ieee80211_bss_conf *bss_conf)
837{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700838 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700839 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530840
841 if (bss_conf->assoc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700842 ath_print(common, ATH_DBG_CONFIG,
843 "Bss Info ASSOC %d, bssid: %pM\n",
844 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530845
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530846 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700847 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700848 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300849
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530850 /*
851 * Request a re-configuration of Beacon related timers
852 * on the receipt of the first Beacon frame (i.e.,
853 * after time sync with the AP).
854 */
Sujith1b04b932010-01-08 10:36:05 +0530855 sc->ps_flags |= PS_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530856
857 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200858 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530859
860 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530861 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530862
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -0700863 sc->sc_flags |= SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800864 ath_start_ani(common);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530865 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700866 ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700867 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +0530868 /* Stop ANI */
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -0700869 sc->sc_flags &= ~SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800870 del_timer_sync(&common->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530871 }
872}
873
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800874void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530875{
Sujithcbe61d8a2009-02-09 13:27:12 +0530876 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700877 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800878 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800879 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530880
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530881 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530882 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +0530883
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530884 if (!ah->curchan)
885 ah->curchan = ath_get_curchannel(sc, sc->hw);
886
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700887 spin_lock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530888 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200889 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800890 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700891 ath_print(common, ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500892 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700893 "reset status %d\n",
894 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530895 }
896 spin_unlock_bh(&sc->sc_resetlock);
897
898 ath_update_txpow(sc);
899 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700900 ath_print(common, ATH_DBG_FATAL,
901 "Unable to restart recv logic\n");
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700902 spin_unlock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530903 return;
904 }
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700905 spin_unlock_bh(&sc->rx.pcu_lock);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530906
907 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200908 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530909
910 /* Re-Enable interrupts */
Pavel Roskin30691682010-03-31 18:05:31 -0400911 ath9k_hw_set_interrupts(ah, ah->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530912
913 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530914 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530915 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530916 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530917
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800918 ieee80211_wake_queues(hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530919 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530920}
921
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800922void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530923{
Sujithcbe61d8a2009-02-09 13:27:12 +0530924 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800925 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800926 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530927
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530928 ath9k_ps_wakeup(sc);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800929 ieee80211_stop_queues(hw);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530930
Vivek Natarajan982723d2010-06-23 12:08:29 +0530931 /*
932 * Keep the LED on when the radio is disabled
933 * during idle unassociated state.
934 */
935 if (!sc->ps_idle) {
936 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
937 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
938 }
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530939
940 /* Disable interrupts */
941 ath9k_hw_set_interrupts(ah, 0);
942
Sujith043a0402009-01-16 21:38:47 +0530943 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700944
945 spin_lock_bh(&sc->rx.pcu_lock);
946
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530947 ath_stoprecv(sc); /* turn off frame recv */
948 ath_flushrecv(sc); /* flush recv queue */
949
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530950 if (!ah->curchan)
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800951 ah->curchan = ath_get_curchannel(sc, hw);
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530952
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530953 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200954 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800955 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700956 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
Pavel Roskinf643e512010-01-29 17:22:12 -0500957 "Unable to reset channel (%u MHz), "
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700958 "reset status %d\n",
959 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530960 }
961 spin_unlock_bh(&sc->sc_resetlock);
962
963 ath9k_hw_phy_disable(ah);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700964
965 spin_unlock_bh(&sc->rx.pcu_lock);
966
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530967 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530968 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700969 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530970}
971
Sujithff37e332008-11-24 12:07:55 +0530972int ath_reset(struct ath_softc *sc, bool retry_tx)
973{
Sujithcbe61d8a2009-02-09 13:27:12 +0530974 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700975 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800976 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800977 int r;
Sujithff37e332008-11-24 12:07:55 +0530978
Sujith2ab81d42009-12-14 16:34:56 +0530979 /* Stop ANI */
980 del_timer_sync(&common->ani.timer);
981
Sujithcc9c3782010-01-08 10:36:09 +0530982 ieee80211_stop_queues(hw);
983
Sujithff37e332008-11-24 12:07:55 +0530984 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530985 ath_drain_all_txq(sc, retry_tx);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -0700986
987 spin_lock_bh(&sc->rx.pcu_lock);
988
Sujithff37e332008-11-24 12:07:55 +0530989 ath_stoprecv(sc);
990 ath_flushrecv(sc);
991
992 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +0200993 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800994 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700995 ath_print(common, ATH_DBG_FATAL,
996 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +0530997 spin_unlock_bh(&sc->sc_resetlock);
998
999 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001000 ath_print(common, ATH_DBG_FATAL,
1001 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301002
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001003 spin_unlock_bh(&sc->rx.pcu_lock);
1004
Sujithff37e332008-11-24 12:07:55 +05301005 /*
1006 * We may be doing a reset in response to a request
1007 * that changes the channel so update any state that
1008 * might change as a result.
1009 */
Sujithff37e332008-11-24 12:07:55 +05301010 ath_update_txpow(sc);
1011
Luis R. Rodriguez52b8ac92010-09-16 15:12:27 -04001012 if ((sc->sc_flags & SC_OP_BEACONS) || !(sc->sc_flags & (SC_OP_OFFCHANNEL)))
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001013 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301014
Pavel Roskin30691682010-03-31 18:05:31 -04001015 ath9k_hw_set_interrupts(ah, ah->imask);
Sujithff37e332008-11-24 12:07:55 +05301016
1017 if (retry_tx) {
1018 int i;
1019 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1020 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301021 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1022 ath_txq_schedule(sc, &sc->tx.txq[i]);
1023 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301024 }
1025 }
1026 }
1027
Sujithcc9c3782010-01-08 10:36:09 +05301028 ieee80211_wake_queues(hw);
1029
Sujith2ab81d42009-12-14 16:34:56 +05301030 /* Start ANI */
1031 ath_start_ani(common);
1032
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001033 return r;
Sujithff37e332008-11-24 12:07:55 +05301034}
1035
Felix Fietkauebe297c2010-06-12 00:33:53 -04001036static int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
Sujithff37e332008-11-24 12:07:55 +05301037{
1038 int qnum;
1039
1040 switch (queue) {
1041 case 0:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001042 qnum = sc->tx.hwq_map[WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301043 break;
1044 case 1:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001045 qnum = sc->tx.hwq_map[WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301046 break;
1047 case 2:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001048 qnum = sc->tx.hwq_map[WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301049 break;
1050 case 3:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001051 qnum = sc->tx.hwq_map[WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301052 break;
1053 default:
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001054 qnum = sc->tx.hwq_map[WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301055 break;
1056 }
1057
1058 return qnum;
1059}
1060
1061int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1062{
1063 int qnum;
1064
1065 switch (queue) {
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001066 case WME_AC_VO:
Sujithff37e332008-11-24 12:07:55 +05301067 qnum = 0;
1068 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001069 case WME_AC_VI:
Sujithff37e332008-11-24 12:07:55 +05301070 qnum = 1;
1071 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001072 case WME_AC_BE:
Sujithff37e332008-11-24 12:07:55 +05301073 qnum = 2;
1074 break;
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001075 case WME_AC_BK:
Sujithff37e332008-11-24 12:07:55 +05301076 qnum = 3;
1077 break;
1078 default:
1079 qnum = -1;
1080 break;
1081 }
1082
1083 return qnum;
1084}
1085
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001086/* XXX: Remove me once we don't depend on ath9k_channel for all
1087 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001088void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1089 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001090{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001091 struct ieee80211_channel *chan = hw->conf.channel;
1092 struct ieee80211_conf *conf = &hw->conf;
1093
1094 ichan->channel = chan->center_freq;
1095 ichan->chan = chan;
1096
1097 if (chan->band == IEEE80211_BAND_2GHZ) {
1098 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05301099 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001100 } else {
1101 ichan->chanmode = CHANNEL_A;
1102 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1103 }
1104
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001105 if (conf_is_ht(conf))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001106 ichan->chanmode = ath_get_extchanmode(sc, chan,
1107 conf->channel_type);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001108}
1109
Sujithff37e332008-11-24 12:07:55 +05301110/**********************/
1111/* mac80211 callbacks */
1112/**********************/
1113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001114static int ath9k_start(struct ieee80211_hw *hw)
1115{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001116 struct ath_wiphy *aphy = hw->priv;
1117 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001118 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001119 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001120 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301121 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301122 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001123
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001124 ath_print(common, ATH_DBG_CONFIG,
1125 "Starting driver with initial channel: %d MHz\n",
1126 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001127
Sujith141b38b2009-02-04 08:10:07 +05301128 mutex_lock(&sc->mutex);
1129
Jouni Malinen9580a222009-03-03 19:23:33 +02001130 if (ath9k_wiphy_started(sc)) {
1131 if (sc->chan_idx == curchan->hw_value) {
1132 /*
1133 * Already on the operational channel, the new wiphy
1134 * can be marked active.
1135 */
1136 aphy->state = ATH_WIPHY_ACTIVE;
1137 ieee80211_wake_queues(hw);
1138 } else {
1139 /*
1140 * Another wiphy is on another channel, start the new
1141 * wiphy in paused state.
1142 */
1143 aphy->state = ATH_WIPHY_PAUSED;
1144 ieee80211_stop_queues(hw);
1145 }
1146 mutex_unlock(&sc->mutex);
1147 return 0;
1148 }
1149 aphy->state = ATH_WIPHY_ACTIVE;
1150
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001151 /* setup initial channel */
1152
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301153 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001154
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301155 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001156
Sujithff37e332008-11-24 12:07:55 +05301157 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001158 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05301159
1160 /*
1161 * The basic interface to setting the hardware in a good
1162 * state is ``reset''. On return the hardware is known to
1163 * be powered up and with interrupts disabled. This must
1164 * be followed by initialization of the appropriate bits
1165 * and then setup of the interrupt mask.
1166 */
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001167 spin_lock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301168 spin_lock_bh(&sc->sc_resetlock);
Felix Fietkau20bd2a02010-07-31 00:12:00 +02001169 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001170 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001171 ath_print(common, ATH_DBG_FATAL,
1172 "Unable to reset hardware; reset status %d "
1173 "(freq %u MHz)\n", r,
1174 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05301175 spin_unlock_bh(&sc->sc_resetlock);
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001176 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith141b38b2009-02-04 08:10:07 +05301177 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001178 }
Sujithff37e332008-11-24 12:07:55 +05301179 spin_unlock_bh(&sc->sc_resetlock);
1180
1181 /*
1182 * This is needed only to setup initial state
1183 * but it's best done after a reset.
1184 */
1185 ath_update_txpow(sc);
1186
1187 /*
1188 * Setup the hardware after reset:
1189 * The receive engine is set going.
1190 * Frame transmit is handled entirely
1191 * in the frame output path; there's nothing to do
1192 * here except setup the interrupt mask.
1193 */
1194 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001195 ath_print(common, ATH_DBG_FATAL,
1196 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05301197 r = -EIO;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001198 spin_unlock_bh(&sc->rx.pcu_lock);
Sujith141b38b2009-02-04 08:10:07 +05301199 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05301200 }
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001201 spin_unlock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301202
1203 /* Setup our intr mask. */
Felix Fietkaub5c804752010-04-15 17:38:48 -04001204 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
1205 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
1206 ATH9K_INT_GLOBAL;
1207
1208 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
Luis R. Rodriguez08578b82010-05-13 13:33:44 -04001209 ah->imask |= ATH9K_INT_RXHP |
1210 ATH9K_INT_RXLP |
1211 ATH9K_INT_BB_WATCHDOG;
Felix Fietkaub5c804752010-04-15 17:38:48 -04001212 else
1213 ah->imask |= ATH9K_INT_RX;
Sujithff37e332008-11-24 12:07:55 +05301214
Felix Fietkau364734f2010-09-14 20:22:44 +02001215 ah->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05301216
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001217 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Pavel Roskin30691682010-03-31 18:05:31 -04001218 ah->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05301219
Sujithff37e332008-11-24 12:07:55 +05301220 sc->sc_flags &= ~SC_OP_INVALID;
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301221 sc->sc_ah->is_monitoring = false;
Sujithff37e332008-11-24 12:07:55 +05301222
1223 /* Disable BMISS interrupt when we're not associated */
Pavel Roskin30691682010-03-31 18:05:31 -04001224 ah->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1225 ath9k_hw_set_interrupts(ah, ah->imask);
Sujithff37e332008-11-24 12:07:55 +05301226
Jouni Malinenbce048d2009-03-03 19:23:28 +02001227 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001228
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001229 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001230
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001231 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
1232 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07001233 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1234 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001235 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05301236
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001237 if (common->bus_ops->bt_coex_prep)
1238 common->bus_ops->bt_coex_prep(common);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001239 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001240 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301241 }
1242
Vivek Natarajan10598c12010-10-30 22:05:13 +05301243 pm_qos_update_request(&ath9k_pm_qos_req, 55);
1244
Sujith141b38b2009-02-04 08:10:07 +05301245mutex_unlock:
1246 mutex_unlock(&sc->mutex);
1247
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001248 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001249}
1250
1251static int ath9k_tx(struct ieee80211_hw *hw,
1252 struct sk_buff *skb)
1253{
Jouni Malinen147583c2008-08-11 14:01:50 +03001254 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02001255 struct ath_wiphy *aphy = hw->priv;
1256 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001257 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05301258 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +01001259 int padpos, padsize;
1260 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Felix Fietkau84642d62010-06-01 21:33:13 +02001261 int qnum;
Sujith528f0c62008-10-29 10:14:26 +05301262
Jouni Malinen8089cc42009-03-03 19:23:38 +02001263 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001264 ath_print(common, ATH_DBG_XMIT,
1265 "ath9k: %s: TX in unexpected wiphy state "
1266 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02001267 goto exit;
1268 }
1269
Gabor Juhos96148322009-07-24 17:27:21 +02001270 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03001271 /*
1272 * mac80211 does not set PM field for normal data frames, so we
1273 * need to update that based on the current PS mode.
1274 */
1275 if (ieee80211_is_data(hdr->frame_control) &&
1276 !ieee80211_is_nullfunc(hdr->frame_control) &&
1277 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001278 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
1279 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03001280 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1281 }
1282 }
1283
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001284 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
1285 /*
1286 * We are using PS-Poll and mac80211 can request TX while in
1287 * power save mode. Need to wake up hardware for the TX to be
1288 * completed and if needed, also for RX of buffered frames.
1289 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001290 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001291 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1292 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001293 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001294 ath_print(common, ATH_DBG_PS,
1295 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +05301296 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001297 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001298 ath_print(common, ATH_DBG_PS,
1299 "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +05301300 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001301 }
1302 /*
1303 * The actual restore operation will happen only after
1304 * the sc_flags bit is cleared. We are just dropping
1305 * the ps_usecount here.
1306 */
1307 ath9k_ps_restore(sc);
1308 }
1309
Sujith528f0c62008-10-29 10:14:26 +05301310 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03001311
1312 /*
1313 * As a temporary workaround, assign seq# here; this will likely need
1314 * to be cleaned up to work better with Beacon transmission and virtual
1315 * BSSes.
1316 */
1317 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Jouni Malinen147583c2008-08-11 14:01:50 +03001318 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05301319 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03001320 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05301321 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03001322 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001323
1324 /* Add the padding after the header if this is not already done */
Benoit Papillault1bc14882009-11-24 15:49:18 +01001325 padpos = ath9k_cmn_padpos(hdr->frame_control);
1326 padsize = padpos & 3;
1327 if (padsize && skb->len>padpos) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001328 if (skb_headroom(skb) < padsize)
1329 return -1;
1330 skb_push(skb, padsize);
Benoit Papillault1bc14882009-11-24 15:49:18 +01001331 memmove(skb->data, skb->data + padsize, padpos);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001332 }
1333
Felix Fietkau84642d62010-06-01 21:33:13 +02001334 qnum = ath_get_hal_qnum(skb_get_queue_mapping(skb), sc);
1335 txctl.txq = &sc->tx.txq[qnum];
Sujith528f0c62008-10-29 10:14:26 +05301336
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001337 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001338
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001339 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001340 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05301341 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001342 }
1343
1344 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301345exit:
1346 dev_kfree_skb_any(skb);
1347 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001348}
1349
1350static void ath9k_stop(struct ieee80211_hw *hw)
1351{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001352 struct ath_wiphy *aphy = hw->priv;
1353 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001354 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001355 struct ath_common *common = ath9k_hw_common(ah);
Rajkumar Manoharan447a42c2010-07-08 12:12:29 +05301356 int i;
Sujith9c84b792008-10-29 10:17:13 +05301357
Sujith4c483812009-08-18 10:51:52 +05301358 mutex_lock(&sc->mutex);
1359
Jouni Malinen9580a222009-03-03 19:23:33 +02001360 aphy->state = ATH_WIPHY_INACTIVE;
1361
Vivek Natarajan9a75c2f2010-06-22 11:52:37 +05301362 if (led_blink)
1363 cancel_delayed_work_sync(&sc->ath_led_blink_work);
1364
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001365 cancel_delayed_work_sync(&sc->tx_complete_work);
Felix Fietkau9f42c2b2010-06-12 00:34:01 -04001366 cancel_work_sync(&sc->paprd_work);
Felix Fietkau347809f2010-07-02 00:09:52 +02001367 cancel_work_sync(&sc->hw_check_work);
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001368
Rajkumar Manoharan447a42c2010-07-08 12:12:29 +05301369 for (i = 0; i < sc->num_sec_wiphy; i++) {
1370 if (sc->sec_wiphy[i])
1371 break;
1372 }
1373
1374 if (i == sc->num_sec_wiphy) {
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001375 cancel_delayed_work_sync(&sc->wiphy_work);
1376 cancel_work_sync(&sc->chan_work);
1377 }
1378
Sujith9c84b792008-10-29 10:17:13 +05301379 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001380 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05301381 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05301382 return;
1383 }
1384
Jouni Malinen9580a222009-03-03 19:23:33 +02001385 if (ath9k_wiphy_started(sc)) {
1386 mutex_unlock(&sc->mutex);
1387 return; /* another wiphy still in use */
1388 }
1389
Sujith3867cf62009-12-23 20:03:27 -05001390 /* Ensure HW is awake when we try to shut it down. */
1391 ath9k_ps_wakeup(sc);
1392
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001393 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001394 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001395 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001396 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301397 }
1398
Sujithff37e332008-11-24 12:07:55 +05301399 /* make sure h/w will not generate any interrupt
1400 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001401 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05301402
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001403 spin_lock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301404 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05301405 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05301406 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001407 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05301408 } else
Sujithb77f4832008-12-07 21:44:03 +05301409 sc->rx.rxlink = NULL;
Luis R. Rodriguez5e848f72010-10-20 16:07:06 -07001410 spin_unlock_bh(&sc->rx.pcu_lock);
Sujithff37e332008-11-24 12:07:55 +05301411
Sujithff37e332008-11-24 12:07:55 +05301412 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001413 ath9k_hw_disable(ah);
1414 ath9k_hw_configpcipowersave(ah, 1, 1);
Sujith3867cf62009-12-23 20:03:27 -05001415 ath9k_ps_restore(sc);
1416
1417 /* Finally, put the chip in FULL SLEEP mode */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001418 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05301419
1420 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001421
Vivek Natarajan10598c12010-10-30 22:05:13 +05301422 pm_qos_update_request(&ath9k_pm_qos_req, PM_QOS_DEFAULT_VALUE);
1423
Sujith141b38b2009-02-04 08:10:07 +05301424 mutex_unlock(&sc->mutex);
1425
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001426 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001427}
1428
1429static int ath9k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001430 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001431{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001432 struct ath_wiphy *aphy = hw->priv;
1433 struct ath_softc *sc = aphy->sc;
Pavel Roskin30691682010-03-31 18:05:31 -04001434 struct ath_hw *ah = sc->sc_ah;
1435 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001436 struct ath_vif *avp = (void *)vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08001437 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001438 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001439
Sujith141b38b2009-02-04 08:10:07 +05301440 mutex_lock(&sc->mutex);
1441
Johannes Berg1ed32e42009-12-23 13:15:45 +01001442 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001443 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08001444 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001445 break;
Bill Jordane51f3ef2010-10-01 11:20:39 -04001446 case NL80211_IFTYPE_WDS:
1447 ic_opmode = NL80211_IFTYPE_WDS;
1448 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001449 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02001450 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04001451 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001452 if (sc->nbcnvifs >= ATH_BCBUF) {
1453 ret = -ENOBUFS;
1454 goto out;
1455 }
Johannes Berg1ed32e42009-12-23 13:15:45 +01001456 ic_opmode = vif->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001457 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001458 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001459 ath_print(common, ATH_DBG_FATAL,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001460 "Interface type %d not yet supported\n", vif->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001461 ret = -EOPNOTSUPP;
1462 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001463 }
1464
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001465 ath_print(common, ATH_DBG_CONFIG,
1466 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467
Sujith17d79042009-02-09 13:27:03 +05301468 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05301469 avp->av_opmode = ic_opmode;
1470 avp->av_bslot = -1;
1471
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001472 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001473
Felix Fietkau364734f2010-09-14 20:22:44 +02001474 ath9k_set_bssid_mask(hw, vif);
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001475
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001476 if (sc->nvifs > 1)
1477 goto out; /* skip global settings for secondary vif */
1478
Sujithb238e902009-03-03 10:16:56 +05301479 if (ic_opmode == NL80211_IFTYPE_AP) {
Pavel Roskin30691682010-03-31 18:05:31 -04001480 ath9k_hw_set_tsfadjust(ah, 1);
Sujithb238e902009-03-03 10:16:56 +05301481 sc->sc_flags |= SC_OP_TSF_RESET;
1482 }
Sujith5640b082008-10-29 10:16:06 +05301483
Sujith5640b082008-10-29 10:16:06 +05301484 /* Set the device opmode */
Pavel Roskin30691682010-03-31 18:05:31 -04001485 ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05301486
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301487 /*
1488 * Enable MIB interrupts when there are hardware phy counters.
1489 * Note we only do this (at the moment) for station mode.
1490 */
Johannes Berg1ed32e42009-12-23 13:15:45 +01001491 if ((vif->type == NL80211_IFTYPE_STATION) ||
1492 (vif->type == NL80211_IFTYPE_ADHOC) ||
1493 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez3448f912010-04-15 17:38:23 -04001494 if (ah->config.enable_ani)
1495 ah->imask |= ATH9K_INT_MIB;
Pavel Roskin30691682010-03-31 18:05:31 -04001496 ah->imask |= ATH9K_INT_TSFOOR;
Sujith4af9cf42009-02-12 10:06:47 +05301497 }
1498
Pavel Roskin30691682010-03-31 18:05:31 -04001499 ath9k_hw_set_interrupts(ah, ah->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301500
Johannes Berg1ed32e42009-12-23 13:15:45 +01001501 if (vif->type == NL80211_IFTYPE_AP ||
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301502 vif->type == NL80211_IFTYPE_ADHOC) {
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001503 sc->sc_flags |= SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001504 ath_start_ani(common);
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001505 }
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001506
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001507out:
Sujith141b38b2009-02-04 08:10:07 +05301508 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001509 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001510}
1511
1512static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001513 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001514{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001515 struct ath_wiphy *aphy = hw->priv;
1516 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001517 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001518 struct ath_vif *avp = (void *)vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001519 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001520
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001521 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001522
Sujith141b38b2009-02-04 08:10:07 +05301523 mutex_lock(&sc->mutex);
1524
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001525 /* Stop ANI */
Vasanthakumar Thiagarajan6c3118e2010-06-23 06:49:21 -07001526 sc->sc_flags &= ~SC_OP_ANI_RUN;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001527 del_timer_sync(&common->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001528
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001529 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04001530 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
1531 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
1532 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001533 ath9k_ps_wakeup(sc);
Sujithb77f4832008-12-07 21:44:03 +05301534 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001535 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001536 }
1537
Felix Fietkau74401772010-01-19 20:51:32 +01001538 ath_beacon_return(sc, avp);
Sujith672840a2008-08-11 14:05:08 +05301539 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001540
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001541 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Johannes Berg1ed32e42009-12-23 13:15:45 +01001542 if (sc->beacon.bslot[i] == vif) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001543 printk(KERN_DEBUG "%s: vif had allocated beacon "
1544 "slot\n", __func__);
1545 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001546 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001547 }
1548 }
1549
Sujith17d79042009-02-09 13:27:03 +05301550 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05301551
1552 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001553}
1554
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301555static void ath9k_enable_ps(struct ath_softc *sc)
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301556{
Pavel Roskin30691682010-03-31 18:05:31 -04001557 struct ath_hw *ah = sc->sc_ah;
1558
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301559 sc->ps_enabled = true;
Pavel Roskin30691682010-03-31 18:05:31 -04001560 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1561 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1562 ah->imask |= ATH9K_INT_TIM_TIMER;
1563 ath9k_hw_set_interrupts(ah, ah->imask);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301564 }
Vasanthakumar Thiagarajanfdf76622010-05-17 18:57:55 -07001565 ath9k_hw_setrxabort(ah, 1);
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301566 }
Senthil Balasubramanian3f7c5c12010-02-03 22:51:13 +05301567}
1568
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301569static void ath9k_disable_ps(struct ath_softc *sc)
1570{
1571 struct ath_hw *ah = sc->sc_ah;
1572
1573 sc->ps_enabled = false;
1574 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1575 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1576 ath9k_hw_setrxabort(ah, 0);
1577 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1578 PS_WAIT_FOR_CAB |
1579 PS_WAIT_FOR_PSPOLL_DATA |
1580 PS_WAIT_FOR_TX_ACK);
1581 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1582 ah->imask &= ~ATH9K_INT_TIM_TIMER;
1583 ath9k_hw_set_interrupts(ah, ah->imask);
1584 }
1585 }
1586
1587}
1588
Johannes Berge8975582008-10-09 12:18:51 +02001589static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001590{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001591 struct ath_wiphy *aphy = hw->priv;
1592 struct ath_softc *sc = aphy->sc;
Felix Fietkau34300982010-10-10 18:21:52 +02001593 struct ath_hw *ah = sc->sc_ah;
1594 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berge8975582008-10-09 12:18:51 +02001595 struct ieee80211_conf *conf = &hw->conf;
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001596 bool disable_radio;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001597
Sujithaa33de02008-12-18 11:40:16 +05301598 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301599
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001600 /*
1601 * Leave this as the first check because we need to turn on the
1602 * radio if it was disabled before prior to processing the rest
1603 * of the changes. Likewise we must only disable the radio towards
1604 * the end.
1605 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001606 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001607 bool enable_radio;
1608 bool all_wiphys_idle;
1609 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001610
1611 spin_lock_bh(&sc->wiphy_lock);
1612 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001613 ath9k_set_wiphy_idle(aphy, idle);
1614
Felix Fietkau11446012010-04-06 12:05:01 -07001615 enable_radio = (!idle && all_wiphys_idle);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001616
1617 /*
1618 * After we unlock here its possible another wiphy
1619 * can be re-renabled so to account for that we will
1620 * only disable the radio toward the end of this routine
1621 * if by then all wiphys are still idle.
1622 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001623 spin_unlock_bh(&sc->wiphy_lock);
1624
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001625 if (enable_radio) {
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +05301626 sc->ps_idle = false;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001627 ath_radio_enable(sc, hw);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001628 ath_print(common, ATH_DBG_CONFIG,
1629 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001630 }
1631 }
1632
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001633 /*
1634 * We just prepare to enable PS. We have to wait until our AP has
1635 * ACK'd our null data frame to disable RX otherwise we'll ignore
1636 * those ACKs and end up retransmitting the same null data frames.
1637 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1638 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301639 if (changed & IEEE80211_CONF_CHANGE_PS) {
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001640 unsigned long flags;
1641 spin_lock_irqsave(&sc->sc_pm_lock, flags);
Senthil Balasubramanianfbab7392010-10-05 20:36:40 +05301642 if (conf->flags & IEEE80211_CONF_PS)
1643 ath9k_enable_ps(sc);
Senthil Balasubramanian845d7082010-10-05 20:36:41 +05301644 else
1645 ath9k_disable_ps(sc);
Luis R. Rodriguez8ab2cd02010-09-16 15:12:26 -04001646 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301647 }
1648
Sujith199afd92010-01-08 10:36:13 +05301649 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1650 if (conf->flags & IEEE80211_CONF_MONITOR) {
1651 ath_print(common, ATH_DBG_CONFIG,
Rajkumar Manoharan5f841b42010-10-27 18:31:15 +05301652 "Monitor mode is enabled\n");
1653 sc->sc_ah->is_monitoring = true;
1654 } else {
1655 ath_print(common, ATH_DBG_CONFIG,
1656 "Monitor mode is disabled\n");
1657 sc->sc_ah->is_monitoring = false;
Sujith199afd92010-01-08 10:36:13 +05301658 }
1659 }
1660
Johannes Berg47979382009-01-07 10:13:27 +01001661 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05301662 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001663 int pos = curchan->hw_value;
Felix Fietkau34300982010-10-10 18:21:52 +02001664 int old_pos = -1;
1665 unsigned long flags;
1666
1667 if (ah->curchan)
1668 old_pos = ah->curchan - &ah->channels[0];
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001669
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001670 aphy->chan_idx = pos;
1671 aphy->chan_is_ht = conf_is_ht(conf);
Felix Fietkau5ee08652010-07-31 00:11:59 +02001672 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
1673 sc->sc_flags |= SC_OP_OFFCHANNEL;
1674 else
1675 sc->sc_flags &= ~SC_OP_OFFCHANNEL;
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001676
Jouni Malinen8089cc42009-03-03 19:23:38 +02001677 if (aphy->state == ATH_WIPHY_SCAN ||
1678 aphy->state == ATH_WIPHY_ACTIVE)
1679 ath9k_wiphy_pause_all_forced(sc, aphy);
1680 else {
1681 /*
1682 * Do not change operational channel based on a paused
1683 * wiphy changes.
1684 */
1685 goto skip_chan_change;
1686 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001687
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001688 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1689 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02001690
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001691 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001692 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05301693
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08001694 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05301695
Felix Fietkau34300982010-10-10 18:21:52 +02001696 /* update survey stats for the old channel before switching */
1697 spin_lock_irqsave(&common->cc_lock, flags);
1698 ath_update_survey_stats(sc);
1699 spin_unlock_irqrestore(&common->cc_lock, flags);
1700
1701 /*
1702 * If the operating channel changes, change the survey in-use flags
1703 * along with it.
1704 * Reset the survey data for the new channel, unless we're switching
1705 * back to the operating channel from an off-channel operation.
1706 */
1707 if (!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1708 sc->cur_survey != &sc->survey[pos]) {
1709
1710 if (sc->cur_survey)
1711 sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE;
1712
1713 sc->cur_survey = &sc->survey[pos];
1714
1715 memset(sc->cur_survey, 0, sizeof(struct survey_info));
1716 sc->cur_survey->filled |= SURVEY_INFO_IN_USE;
1717 } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) {
1718 memset(&sc->survey[pos], 0, sizeof(struct survey_info));
1719 }
1720
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001721 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001722 ath_print(common, ATH_DBG_FATAL,
1723 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301724 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05301725 return -EINVAL;
1726 }
Felix Fietkau34300982010-10-10 18:21:52 +02001727
1728 /*
1729 * The most recent snapshot of channel->noisefloor for the old
1730 * channel is only available after the hardware reset. Copy it to
1731 * the survey stats now.
1732 */
1733 if (old_pos >= 0)
1734 ath_update_survey_nf(sc, old_pos);
Sujith094d05d2008-12-12 11:57:43 +05301735 }
Sujith86b89ee2008-08-07 10:54:57 +05301736
Jouni Malinen8089cc42009-03-03 19:23:38 +02001737skip_chan_change:
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001738 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Sujith17d79042009-02-09 13:27:03 +05301739 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001740 ath_update_txpow(sc);
1741 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001742
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001743 spin_lock_bh(&sc->wiphy_lock);
1744 disable_radio = ath9k_all_wiphys_idle(sc);
1745 spin_unlock_bh(&sc->wiphy_lock);
1746
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001747 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001748 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Vivek Natarajan1dbfd9d2010-01-29 16:56:51 +05301749 sc->ps_idle = true;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001750 ath_radio_disable(sc, hw);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001751 }
1752
Sujithaa33de02008-12-18 11:40:16 +05301753 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301754
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001755 return 0;
1756}
1757
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001758#define SUPPORTED_FILTERS \
1759 (FIF_PROMISC_IN_BSS | \
1760 FIF_ALLMULTI | \
1761 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001762 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001763 FIF_OTHER_BSS | \
1764 FIF_BCN_PRBRESP_PROMISC | \
Jouni Malinen9c1d8e42010-10-13 17:29:31 +03001765 FIF_PROBE_REQ | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001766 FIF_FCSFAIL)
1767
Sujith7dcfdcd2008-08-11 14:03:13 +05301768/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769static void ath9k_configure_filter(struct ieee80211_hw *hw,
1770 unsigned int changed_flags,
1771 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001772 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001774 struct ath_wiphy *aphy = hw->priv;
1775 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05301776 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001777
1778 changed_flags &= SUPPORTED_FILTERS;
1779 *total_flags &= SUPPORTED_FILTERS;
1780
Sujithb77f4832008-12-07 21:44:03 +05301781 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001782 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301783 rfilt = ath_calcrxfilter(sc);
1784 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001785 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301786
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001787 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
1788 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001789}
1790
Johannes Berg4ca77862010-02-19 19:06:56 +01001791static int ath9k_sta_add(struct ieee80211_hw *hw,
1792 struct ieee80211_vif *vif,
1793 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001794{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001795 struct ath_wiphy *aphy = hw->priv;
1796 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001797
Johannes Berg4ca77862010-02-19 19:06:56 +01001798 ath_node_attach(sc, sta);
1799
1800 return 0;
1801}
1802
1803static int ath9k_sta_remove(struct ieee80211_hw *hw,
1804 struct ieee80211_vif *vif,
1805 struct ieee80211_sta *sta)
1806{
1807 struct ath_wiphy *aphy = hw->priv;
1808 struct ath_softc *sc = aphy->sc;
1809
1810 ath_node_detach(sc, sta);
1811
1812 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001813}
1814
Sujith141b38b2009-02-04 08:10:07 +05301815static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001816 const struct ieee80211_tx_queue_params *params)
1817{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001818 struct ath_wiphy *aphy = hw->priv;
1819 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001820 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05301821 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001822 int ret = 0, qnum;
1823
1824 if (queue >= WME_NUM_AC)
1825 return 0;
1826
Sujith141b38b2009-02-04 08:10:07 +05301827 mutex_lock(&sc->mutex);
1828
Sujith1ffb0612009-03-30 15:28:46 +05301829 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1830
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001831 qi.tqi_aifs = params->aifs;
1832 qi.tqi_cwmin = params->cw_min;
1833 qi.tqi_cwmax = params->cw_max;
1834 qi.tqi_burstTime = params->txop;
1835 qnum = ath_get_hal_qnum(queue, sc);
1836
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001837 ath_print(common, ATH_DBG_CONFIG,
1838 "Configure tx [queue/halq] [%d/%d], "
1839 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1840 queue, qnum, params->aifs, params->cw_min,
1841 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001842
1843 ret = ath_txq_update(sc, qnum, &qi);
1844 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001845 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001846
Vivek Natarajan94db2932009-11-25 12:01:54 +05301847 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
Felix Fietkau1d2231e2010-06-12 00:33:51 -04001848 if ((qnum == sc->tx.hwq_map[WME_AC_BE]) && !ret)
Vivek Natarajan94db2932009-11-25 12:01:54 +05301849 ath_beaconq_config(sc);
1850
Sujith141b38b2009-02-04 08:10:07 +05301851 mutex_unlock(&sc->mutex);
1852
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853 return ret;
1854}
1855
1856static int ath9k_set_key(struct ieee80211_hw *hw,
1857 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001858 struct ieee80211_vif *vif,
1859 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001860 struct ieee80211_key_conf *key)
1861{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001862 struct ath_wiphy *aphy = hw->priv;
1863 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001864 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001865 int ret = 0;
1866
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001867 if (modparam_nohwcrypt)
1868 return -ENOSPC;
1869
Sujith141b38b2009-02-04 08:10:07 +05301870 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301871 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001872 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873
1874 switch (cmd) {
1875 case SET_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001876 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001877 if (ret >= 0) {
1878 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001879 /* push IV and Michael MIC generation to stack */
1880 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Johannes Berg97359d12010-08-10 09:46:38 +02001881 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301882 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Johannes Berg97359d12010-08-10 09:46:38 +02001883 if (sc->sc_ah->sw_mgmt_crypto &&
1884 key->cipher == WLAN_CIPHER_SUITE_CCMP)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001885 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001886 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001887 }
1888 break;
1889 case DISABLE_KEY:
Bruno Randolf040e5392010-09-08 16:05:04 +09001890 ath_key_delete(common, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891 break;
1892 default:
1893 ret = -EINVAL;
1894 }
1895
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301896 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301897 mutex_unlock(&sc->mutex);
1898
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899 return ret;
1900}
1901
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001902static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1903 struct ieee80211_vif *vif,
1904 struct ieee80211_bss_conf *bss_conf,
1905 u32 changed)
1906{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001907 struct ath_wiphy *aphy = hw->priv;
1908 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001909 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001910 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001911 struct ath_vif *avp = (void *)vif->drv_priv;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001912 int slottime;
Sujithc6089cc2009-11-16 11:40:48 +05301913 int error;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001914
Sujith141b38b2009-02-04 08:10:07 +05301915 mutex_lock(&sc->mutex);
1916
Sujithc6089cc2009-11-16 11:40:48 +05301917 if (changed & BSS_CHANGED_BSSID) {
1918 /* Set BSSID */
1919 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1920 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001921 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001922 ath9k_hw_write_associd(ah);
Sujithc6089cc2009-11-16 11:40:48 +05301923
1924 /* Set aggregation protection mode parameters */
1925 sc->config.ath_aggr_prot = 0;
1926
1927 /* Only legacy IBSS for now */
1928 if (vif->type == NL80211_IFTYPE_ADHOC)
1929 ath_update_chainmask(sc, 0);
1930
1931 ath_print(common, ATH_DBG_CONFIG,
1932 "BSSID: %pM aid: 0x%x\n",
1933 common->curbssid, common->curaid);
1934
1935 /* need to reconfigure the beacon */
1936 sc->sc_flags &= ~SC_OP_BEACONS ;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001937 }
1938
Sujithc6089cc2009-11-16 11:40:48 +05301939 /* Enable transmission of beacons (AP, IBSS, MESH) */
1940 if ((changed & BSS_CHANGED_BEACON) ||
1941 ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
1942 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1943 error = ath_beacon_alloc(aphy, vif);
1944 if (!error)
1945 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001946 }
1947
Felix Fietkau0005baf2010-01-15 02:33:40 +01001948 if (changed & BSS_CHANGED_ERP_SLOT) {
1949 if (bss_conf->use_short_slot)
1950 slottime = 9;
1951 else
1952 slottime = 20;
1953 if (vif->type == NL80211_IFTYPE_AP) {
1954 /*
1955 * Defer update, so that connected stations can adjust
1956 * their settings at the same time.
1957 * See beacon.c for more details
1958 */
1959 sc->beacon.slottime = slottime;
1960 sc->beacon.updateslot = UPDATE;
1961 } else {
1962 ah->slottime = slottime;
1963 ath9k_hw_init_global_settings(ah);
1964 }
1965 }
1966
Sujithc6089cc2009-11-16 11:40:48 +05301967 /* Disable transmission of beacons */
1968 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
1969 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1970
1971 if (changed & BSS_CHANGED_BEACON_INT) {
1972 sc->beacon_interval = bss_conf->beacon_int;
1973 /*
1974 * In case of AP mode, the HW TSF has to be reset
1975 * when the beacon interval changes.
1976 */
1977 if (vif->type == NL80211_IFTYPE_AP) {
1978 sc->sc_flags |= SC_OP_TSF_RESET;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001979 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001980 error = ath_beacon_alloc(aphy, vif);
1981 if (!error)
1982 ath_beacon_config(sc, vif);
Sujithc6089cc2009-11-16 11:40:48 +05301983 } else {
1984 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001985 }
1986 }
1987
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001988 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001989 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1990 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001991 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05301992 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 else
Sujith672840a2008-08-11 14:05:08 +05301994 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001995 }
1996
1997 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001998 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1999 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002000 if (bss_conf->use_cts_prot &&
2001 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302002 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002003 else
Sujith672840a2008-08-11 14:05:08 +05302004 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002005 }
2006
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002007 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002008 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002009 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302010 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002011 }
Sujith141b38b2009-02-04 08:10:07 +05302012
2013 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014}
2015
2016static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2017{
2018 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002019 struct ath_wiphy *aphy = hw->priv;
2020 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002021
Sujith141b38b2009-02-04 08:10:07 +05302022 mutex_lock(&sc->mutex);
2023 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2024 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002025
2026 return tsf;
2027}
2028
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002029static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2030{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002031 struct ath_wiphy *aphy = hw->priv;
2032 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002033
Sujith141b38b2009-02-04 08:10:07 +05302034 mutex_lock(&sc->mutex);
2035 ath9k_hw_settsf64(sc->sc_ah, tsf);
2036 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002037}
2038
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002039static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2040{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002041 struct ath_wiphy *aphy = hw->priv;
2042 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002043
Sujith141b38b2009-02-04 08:10:07 +05302044 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002045
2046 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05302047 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002048 ath9k_ps_restore(sc);
2049
Sujith141b38b2009-02-04 08:10:07 +05302050 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051}
2052
2053static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01002054 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05302055 enum ieee80211_ampdu_mlme_action action,
2056 struct ieee80211_sta *sta,
2057 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002058{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002059 struct ath_wiphy *aphy = hw->priv;
2060 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002061 int ret = 0;
2062
Johannes Berg85ad1812010-06-10 10:21:49 +02002063 local_bh_disable();
2064
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002065 switch (action) {
2066 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05302067 if (!(sc->sc_flags & SC_OP_RXAGGR))
2068 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002069 break;
2070 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071 break;
2072 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002073 ath9k_ps_wakeup(sc);
Felix Fietkau231c3a12010-09-20 19:35:28 +02002074 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
2075 if (!ret)
2076 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002077 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002078 break;
2079 case IEEE80211_AMPDU_TX_STOP:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002080 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05302081 ath_tx_aggr_stop(sc, sta, tid);
Johannes Bergc951ad32009-11-16 12:00:38 +01002082 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002083 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002084 break;
Johannes Bergb1720232009-03-23 17:28:39 +01002085 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002086 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05302087 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05002088 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05302089 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002090 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002091 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
2092 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002093 }
2094
Johannes Berg85ad1812010-06-10 10:21:49 +02002095 local_bh_enable();
2096
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002097 return ret;
2098}
2099
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002100static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
2101 struct survey_info *survey)
2102{
2103 struct ath_wiphy *aphy = hw->priv;
2104 struct ath_softc *sc = aphy->sc;
Felix Fietkau34300982010-10-10 18:21:52 +02002105 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Felix Fietkau39162db2010-09-29 19:12:06 +02002106 struct ieee80211_supported_band *sband;
Felix Fietkau34300982010-10-10 18:21:52 +02002107 struct ieee80211_channel *chan;
2108 unsigned long flags;
2109 int pos;
2110
2111 spin_lock_irqsave(&common->cc_lock, flags);
2112 if (idx == 0)
2113 ath_update_survey_stats(sc);
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002114
Felix Fietkau39162db2010-09-29 19:12:06 +02002115 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
2116 if (sband && idx >= sband->n_channels) {
2117 idx -= sband->n_channels;
2118 sband = NULL;
2119 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002120
Felix Fietkau39162db2010-09-29 19:12:06 +02002121 if (!sband)
2122 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
2123
Felix Fietkau34300982010-10-10 18:21:52 +02002124 if (!sband || idx >= sband->n_channels) {
2125 spin_unlock_irqrestore(&common->cc_lock, flags);
2126 return -ENOENT;
Felix Fietkau4f1a5a42010-09-29 17:15:28 +02002127 }
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002128
Felix Fietkau34300982010-10-10 18:21:52 +02002129 chan = &sband->channels[idx];
2130 pos = chan->hw_value;
2131 memcpy(survey, &sc->survey[pos], sizeof(*survey));
2132 survey->channel = chan;
2133 spin_unlock_irqrestore(&common->cc_lock, flags);
2134
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002135 return 0;
2136}
2137
Sujith0c98de62009-03-03 10:16:45 +05302138static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2139{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002140 struct ath_wiphy *aphy = hw->priv;
2141 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302142
Sujith3d832612009-08-21 12:00:28 +05302143 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002144 if (ath9k_wiphy_scanning(sc)) {
Jouni Malinen8089cc42009-03-03 19:23:38 +02002145 /*
Luis R. Rodriguez30888332010-07-27 16:33:06 -04002146 * There is a race here in mac80211 but fixing it requires
2147 * we revisit how we handle the scan complete callback.
2148 * After mac80211 fixes we will not have configured hardware
2149 * to the home channel nor would we have configured the RX
2150 * filter yet.
Jouni Malinen8089cc42009-03-03 19:23:38 +02002151 */
Sujith3d832612009-08-21 12:00:28 +05302152 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002153 return;
2154 }
2155
2156 aphy->state = ATH_WIPHY_SCAN;
2157 ath9k_wiphy_pause_all_forced(sc, aphy);
Sujith3d832612009-08-21 12:00:28 +05302158 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302159}
2160
Luis R. Rodriguez30888332010-07-27 16:33:06 -04002161/*
2162 * XXX: this requires a revisit after the driver
2163 * scan_complete gets moved to another place/removed in mac80211.
2164 */
Sujith0c98de62009-03-03 10:16:45 +05302165static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2166{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002167 struct ath_wiphy *aphy = hw->priv;
2168 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302169
Sujith3d832612009-08-21 12:00:28 +05302170 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002171 aphy->state = ATH_WIPHY_ACTIVE;
Sujith3d832612009-08-21 12:00:28 +05302172 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302173}
2174
Felix Fietkaue239d852010-01-15 02:34:58 +01002175static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
2176{
2177 struct ath_wiphy *aphy = hw->priv;
2178 struct ath_softc *sc = aphy->sc;
2179 struct ath_hw *ah = sc->sc_ah;
2180
2181 mutex_lock(&sc->mutex);
2182 ah->coverage_class = coverage_class;
2183 ath9k_hw_init_global_settings(ah);
2184 mutex_unlock(&sc->mutex);
2185}
2186
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002187struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002188 .tx = ath9k_tx,
2189 .start = ath9k_start,
2190 .stop = ath9k_stop,
2191 .add_interface = ath9k_add_interface,
2192 .remove_interface = ath9k_remove_interface,
2193 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002194 .configure_filter = ath9k_configure_filter,
Johannes Berg4ca77862010-02-19 19:06:56 +01002195 .sta_add = ath9k_sta_add,
2196 .sta_remove = ath9k_sta_remove,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002197 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002198 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002199 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002200 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002201 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002202 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002203 .ampdu_action = ath9k_ampdu_action,
Benoit Papillault62dad5b2010-04-28 00:08:24 +02002204 .get_survey = ath9k_get_survey,
Sujith0c98de62009-03-03 10:16:45 +05302205 .sw_scan_start = ath9k_sw_scan_start,
2206 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302207 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002208 .set_coverage_class = ath9k_set_coverage_class,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002209};