blob: 693555728eaba48c958a393a8b35c6c3f5481c32 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070017#include <linux/nl80211.h>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070019#include "btcoex.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021static char *dev_info = "ath9k";
22
23MODULE_AUTHOR("Atheros Communications");
24MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
25MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
26MODULE_LICENSE("Dual BSD/GPL");
27
Jouni Malinenb3bd89c2009-02-24 13:42:01 +020028static int modparam_nohwcrypt;
29module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
30MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
31
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080032/* We use the hw_value as an index into our private channel structure */
33
34#define CHAN2G(_freq, _idx) { \
35 .center_freq = (_freq), \
36 .hw_value = (_idx), \
Luis R. Rodriguezeeddfd92009-05-19 17:49:46 -040037 .max_power = 20, \
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080038}
39
40#define CHAN5G(_freq, _idx) { \
41 .band = IEEE80211_BAND_5GHZ, \
42 .center_freq = (_freq), \
43 .hw_value = (_idx), \
Luis R. Rodriguezeeddfd92009-05-19 17:49:46 -040044 .max_power = 20, \
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080045}
46
47/* Some 2 GHz radios are actually tunable on 2312-2732
48 * on 5 MHz steps, we support the channels which we know
49 * we have calibration data for all cards though to make
50 * this static */
51static struct ieee80211_channel ath9k_2ghz_chantable[] = {
52 CHAN2G(2412, 0), /* Channel 1 */
53 CHAN2G(2417, 1), /* Channel 2 */
54 CHAN2G(2422, 2), /* Channel 3 */
55 CHAN2G(2427, 3), /* Channel 4 */
56 CHAN2G(2432, 4), /* Channel 5 */
57 CHAN2G(2437, 5), /* Channel 6 */
58 CHAN2G(2442, 6), /* Channel 7 */
59 CHAN2G(2447, 7), /* Channel 8 */
60 CHAN2G(2452, 8), /* Channel 9 */
61 CHAN2G(2457, 9), /* Channel 10 */
62 CHAN2G(2462, 10), /* Channel 11 */
63 CHAN2G(2467, 11), /* Channel 12 */
64 CHAN2G(2472, 12), /* Channel 13 */
65 CHAN2G(2484, 13), /* Channel 14 */
66};
67
68/* Some 5 GHz radios are actually tunable on XXXX-YYYY
69 * on 5 MHz steps, we support the channels which we know
70 * we have calibration data for all cards though to make
71 * this static */
72static struct ieee80211_channel ath9k_5ghz_chantable[] = {
73 /* _We_ call this UNII 1 */
74 CHAN5G(5180, 14), /* Channel 36 */
75 CHAN5G(5200, 15), /* Channel 40 */
76 CHAN5G(5220, 16), /* Channel 44 */
77 CHAN5G(5240, 17), /* Channel 48 */
78 /* _We_ call this UNII 2 */
79 CHAN5G(5260, 18), /* Channel 52 */
80 CHAN5G(5280, 19), /* Channel 56 */
81 CHAN5G(5300, 20), /* Channel 60 */
82 CHAN5G(5320, 21), /* Channel 64 */
83 /* _We_ call this "Middle band" */
84 CHAN5G(5500, 22), /* Channel 100 */
85 CHAN5G(5520, 23), /* Channel 104 */
86 CHAN5G(5540, 24), /* Channel 108 */
87 CHAN5G(5560, 25), /* Channel 112 */
88 CHAN5G(5580, 26), /* Channel 116 */
89 CHAN5G(5600, 27), /* Channel 120 */
90 CHAN5G(5620, 28), /* Channel 124 */
91 CHAN5G(5640, 29), /* Channel 128 */
92 CHAN5G(5660, 30), /* Channel 132 */
93 CHAN5G(5680, 31), /* Channel 136 */
94 CHAN5G(5700, 32), /* Channel 140 */
95 /* _We_ call this UNII 3 */
96 CHAN5G(5745, 33), /* Channel 149 */
97 CHAN5G(5765, 34), /* Channel 153 */
98 CHAN5G(5785, 35), /* Channel 157 */
99 CHAN5G(5805, 36), /* Channel 161 */
100 CHAN5G(5825, 37), /* Channel 165 */
101};
102
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800103static void ath_cache_conf_rate(struct ath_softc *sc,
104 struct ieee80211_conf *conf)
Sujithff37e332008-11-24 12:07:55 +0530105{
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800106 switch (conf->channel->band) {
107 case IEEE80211_BAND_2GHZ:
108 if (conf_is_ht20(conf))
109 sc->cur_rate_table =
110 sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
111 else if (conf_is_ht40_minus(conf))
112 sc->cur_rate_table =
113 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
114 else if (conf_is_ht40_plus(conf))
115 sc->cur_rate_table =
116 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800117 else
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800118 sc->cur_rate_table =
119 sc->hw_rate_table[ATH9K_MODE_11G];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800120 break;
121 case IEEE80211_BAND_5GHZ:
122 if (conf_is_ht20(conf))
123 sc->cur_rate_table =
124 sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
125 else if (conf_is_ht40_minus(conf))
126 sc->cur_rate_table =
127 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
128 else if (conf_is_ht40_plus(conf))
129 sc->cur_rate_table =
130 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
131 else
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800132 sc->cur_rate_table =
133 sc->hw_rate_table[ATH9K_MODE_11A];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800134 break;
135 default:
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800136 BUG_ON(1);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800137 break;
138 }
Sujithff37e332008-11-24 12:07:55 +0530139}
140
141static void ath_update_txpow(struct ath_softc *sc)
142{
Sujithcbe61d82009-02-09 13:27:12 +0530143 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530144 u32 txpow;
145
Sujith17d79042009-02-09 13:27:03 +0530146 if (sc->curtxpow != sc->config.txpowlimit) {
147 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +0530148 /* read back in case value is clamped */
149 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
Sujith17d79042009-02-09 13:27:03 +0530150 sc->curtxpow = txpow;
Sujithff37e332008-11-24 12:07:55 +0530151 }
152}
153
154static u8 parse_mpdudensity(u8 mpdudensity)
155{
156 /*
157 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
158 * 0 for no restriction
159 * 1 for 1/4 us
160 * 2 for 1/2 us
161 * 3 for 1 us
162 * 4 for 2 us
163 * 5 for 4 us
164 * 6 for 8 us
165 * 7 for 16 us
166 */
167 switch (mpdudensity) {
168 case 0:
169 return 0;
170 case 1:
171 case 2:
172 case 3:
173 /* Our lower layer calculations limit our precision to
174 1 microsecond */
175 return 1;
176 case 4:
177 return 2;
178 case 5:
179 return 4;
180 case 6:
181 return 8;
182 case 7:
183 return 16;
184 default:
185 return 0;
186 }
187}
188
189static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
190{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400191 const struct ath_rate_table *rate_table = NULL;
Sujithff37e332008-11-24 12:07:55 +0530192 struct ieee80211_supported_band *sband;
193 struct ieee80211_rate *rate;
194 int i, maxrates;
195
196 switch (band) {
197 case IEEE80211_BAND_2GHZ:
198 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
199 break;
200 case IEEE80211_BAND_5GHZ:
201 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
202 break;
203 default:
204 break;
205 }
206
207 if (rate_table == NULL)
208 return;
209
210 sband = &sc->sbands[band];
211 rate = sc->rates[band];
212
213 if (rate_table->rate_cnt > ATH_RATE_MAX)
214 maxrates = ATH_RATE_MAX;
215 else
216 maxrates = rate_table->rate_cnt;
217
218 for (i = 0; i < maxrates; i++) {
219 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
220 rate[i].hw_value = rate_table->info[i].ratecode;
Sujithf46730d2009-01-27 13:51:03 +0530221 if (rate_table->info[i].short_preamble) {
222 rate[i].hw_value_short = rate_table->info[i].ratecode |
223 rate_table->info[i].short_preamble;
224 rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
225 }
Sujithff37e332008-11-24 12:07:55 +0530226 sband->n_bitrates++;
Sujithf46730d2009-01-27 13:51:03 +0530227
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700228 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
Sujith04bd46382008-11-28 22:18:05 +0530229 rate[i].bitrate / 10, rate[i].hw_value);
Sujithff37e332008-11-24 12:07:55 +0530230 }
231}
232
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530233static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
234 struct ieee80211_hw *hw)
235{
236 struct ieee80211_channel *curchan = hw->conf.channel;
237 struct ath9k_channel *channel;
238 u8 chan_idx;
239
240 chan_idx = curchan->hw_value;
241 channel = &sc->sc_ah->channels[chan_idx];
242 ath9k_update_ichannel(sc, hw, channel);
243 return channel;
244}
245
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700246static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700247{
248 unsigned long flags;
249 bool ret;
250
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700251 spin_lock_irqsave(&sc->sc_pm_lock, flags);
252 ret = ath9k_hw_setpower(sc->sc_ah, mode);
253 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700254
255 return ret;
256}
257
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700258void ath9k_ps_wakeup(struct ath_softc *sc)
259{
260 unsigned long flags;
261
262 spin_lock_irqsave(&sc->sc_pm_lock, flags);
263 if (++sc->ps_usecount != 1)
264 goto unlock;
265
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700266 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700267
268 unlock:
269 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
270}
271
272void ath9k_ps_restore(struct ath_softc *sc)
273{
274 unsigned long flags;
275
276 spin_lock_irqsave(&sc->sc_pm_lock, flags);
277 if (--sc->ps_usecount != 0)
278 goto unlock;
279
280 if (sc->ps_enabled &&
281 !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
282 SC_OP_WAIT_FOR_CAB |
283 SC_OP_WAIT_FOR_PSPOLL_DATA |
284 SC_OP_WAIT_FOR_TX_ACK)))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700285 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700286
287 unlock:
288 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
289}
290
Sujithff37e332008-11-24 12:07:55 +0530291/*
292 * Set/change channels. If the channel is really being changed, it's done
293 * by reseting the chip. To accomplish this we must first cleanup any pending
294 * DMA, then restart stuff.
295*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200296int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
297 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530298{
Sujithcbe61d82009-02-09 13:27:12 +0530299 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530300 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800301 struct ieee80211_channel *channel = hw->conf.channel;
302 int r;
Sujithff37e332008-11-24 12:07:55 +0530303
304 if (sc->sc_flags & SC_OP_INVALID)
305 return -EIO;
306
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530307 ath9k_ps_wakeup(sc);
308
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800309 /*
310 * This is only performed if the channel settings have
311 * actually changed.
312 *
313 * To switch channels clear any pending DMA operations;
314 * wait long enough for the RX fifo to drain, reset the
315 * hardware at the new frequency, and then re-enable
316 * the relevant bits of the h/w.
317 */
318 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530319 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800320 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530321
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800322 /* XXX: do not flush receive queue here. We don't want
323 * to flush data frames already in queue because of
324 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530325
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800326 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
327 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530328
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700329 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800330 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
Sujith2660b812009-02-09 13:27:26 +0530331 sc->sc_ah->curchan->channel,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800332 channel->center_freq, sc->tx_chan_width);
Sujith99405f92008-11-24 12:08:35 +0530333
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800334 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800335
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800336 r = ath9k_hw_reset(ah, hchan, fastcc);
337 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700338 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800339 "Unable to reset channel (%u Mhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +0530340 "reset status %d\n",
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800341 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530342 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200343 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530344 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800345 spin_unlock_bh(&sc->sc_resetlock);
346
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800347 sc->sc_flags &= ~SC_OP_FULL_RESET;
348
349 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700350 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800351 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200352 r = -EIO;
353 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800354 }
355
356 ath_cache_conf_rate(sc, &hw->conf);
357 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530358 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200359
360 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530361 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200362 return r;
Sujithff37e332008-11-24 12:07:55 +0530363}
364
365/*
366 * This routine performs the periodic noise floor calibration function
367 * that is used to adjust and optimize the chip performance. This
368 * takes environmental changes (location, temperature) into account.
369 * When the task is complete, it reschedules itself depending on the
370 * appropriate interval that was calculated.
371 */
372static void ath_ani_calibrate(unsigned long data)
373{
Sujith20977d32009-02-20 15:13:28 +0530374 struct ath_softc *sc = (struct ath_softc *)data;
375 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530376 bool longcal = false;
377 bool shortcal = false;
378 bool aniflag = false;
379 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530380 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530381
Sujith20977d32009-02-20 15:13:28 +0530382 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
383 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530384
385 /*
386 * don't calibrate when we're scanning.
387 * we are most likely not on our home channel.
388 */
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530389 spin_lock(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +0530390 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530391 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530392
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300393 /* Only calibrate if awake */
394 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
395 goto set_timer;
396
397 ath9k_ps_wakeup(sc);
398
Sujithff37e332008-11-24 12:07:55 +0530399 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530400 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530401 longcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700402 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530403 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530404 }
405
Sujith17d79042009-02-09 13:27:03 +0530406 /* Short calibration applies only while caldone is false */
407 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530408 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530409 shortcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700410 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530411 sc->ani.shortcal_timer = timestamp;
412 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530413 }
414 } else {
Sujith17d79042009-02-09 13:27:03 +0530415 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530416 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530417 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
418 if (sc->ani.caldone)
419 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530420 }
421 }
422
423 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530424 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530425 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530426 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530427 }
428
429 /* Skip all processing if there's nothing to do. */
430 if (longcal || shortcal || aniflag) {
431 /* Call ANI routine if necessary */
432 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530433 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530434
435 /* Perform calibration if necessary */
436 if (longcal || shortcal) {
Sujith379f0442009-04-13 21:56:48 +0530437 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
438 sc->rx_chainmask, longcal);
Sujithff37e332008-11-24 12:07:55 +0530439
Sujith379f0442009-04-13 21:56:48 +0530440 if (longcal)
441 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
442 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530443
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700444 DPRINTF(sc->sc_ah, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
Sujith379f0442009-04-13 21:56:48 +0530445 ah->curchan->channel, ah->curchan->channelFlags,
446 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530447 }
448 }
449
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300450 ath9k_ps_restore(sc);
451
Sujith20977d32009-02-20 15:13:28 +0530452set_timer:
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530453 spin_unlock(&sc->ani_lock);
Sujithff37e332008-11-24 12:07:55 +0530454 /*
455 * Set timer interval based on previous results.
456 * The interval must be the shortest necessary to satisfy ANI,
457 * short calibration and long calibration.
458 */
Sujithaac92072008-12-02 18:37:54 +0530459 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530460 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530461 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530462 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530463 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530464
Sujith17d79042009-02-09 13:27:03 +0530465 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530466}
467
Sujith415f7382009-04-13 21:56:46 +0530468static void ath_start_ani(struct ath_softc *sc)
469{
470 unsigned long timestamp = jiffies_to_msecs(jiffies);
471
472 sc->ani.longcal_timer = timestamp;
473 sc->ani.shortcal_timer = timestamp;
474 sc->ani.checkani_timer = timestamp;
475
476 mod_timer(&sc->ani.timer,
477 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
478}
479
Sujithff37e332008-11-24 12:07:55 +0530480/*
481 * Update tx/rx chainmask. For legacy association,
482 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530483 * the chainmask configuration, for bt coexistence, use
484 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530485 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200486void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530487{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700488 struct ath_hw *ah = sc->sc_ah;
489
Sujith3d832612009-08-21 12:00:28 +0530490 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700491 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Sujith2660b812009-02-09 13:27:26 +0530492 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
493 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530494 } else {
Sujith17d79042009-02-09 13:27:03 +0530495 sc->tx_chainmask = 1;
496 sc->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530497 }
498
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700499 DPRINTF(ah, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
Sujith17d79042009-02-09 13:27:03 +0530500 sc->tx_chainmask, sc->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530501}
502
503static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
504{
505 struct ath_node *an;
506
507 an = (struct ath_node *)sta->drv_priv;
508
Sujith87792ef2009-03-30 15:28:48 +0530509 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530510 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530511 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530512 sta->ht_cap.ampdu_factor);
513 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400514 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530515 }
Sujithff37e332008-11-24 12:07:55 +0530516}
517
518static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
519{
520 struct ath_node *an = (struct ath_node *)sta->drv_priv;
521
522 if (sc->sc_flags & SC_OP_TXAGGR)
523 ath_tx_node_cleanup(sc, an);
524}
525
526static void ath9k_tasklet(unsigned long data)
527{
528 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700529 struct ath_hw *ah = sc->sc_ah;
530
Sujith17d79042009-02-09 13:27:03 +0530531 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530532
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400533 ath9k_ps_wakeup(sc);
534
Sujithff37e332008-11-24 12:07:55 +0530535 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530536 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400537 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530538 return;
Sujithff37e332008-11-24 12:07:55 +0530539 }
540
Sujith063d8be2009-03-30 15:28:49 +0530541 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
542 spin_lock_bh(&sc->rx.rxflushlock);
543 ath_rx_tasklet(sc, 0);
544 spin_unlock_bh(&sc->rx.rxflushlock);
545 }
546
547 if (status & ATH9K_INT_TX)
548 ath_tx_tasklet(sc);
549
Gabor Juhos96148322009-07-24 17:27:21 +0200550 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300551 /*
552 * TSF sync does not look correct; remain awake to sync with
553 * the next Beacon.
554 */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700555 DPRINTF(ah, ATH_DBG_PS, "TSFOOR - Sync with next Beacon\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300556 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300557 }
558
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700559 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530560 if (status & ATH9K_INT_GENTIMER)
561 ath_gen_timer_isr(sc->sc_ah);
562
Sujithff37e332008-11-24 12:07:55 +0530563 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700564 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400565 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530566}
567
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100568irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530569{
Sujith063d8be2009-03-30 15:28:49 +0530570#define SCHED_INTR ( \
571 ATH9K_INT_FATAL | \
572 ATH9K_INT_RXORN | \
573 ATH9K_INT_RXEOL | \
574 ATH9K_INT_RX | \
575 ATH9K_INT_TX | \
576 ATH9K_INT_BMISS | \
577 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530578 ATH9K_INT_TSFOOR | \
579 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530580
Sujithff37e332008-11-24 12:07:55 +0530581 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530582 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530583 enum ath9k_int status;
584 bool sched = false;
585
Sujith063d8be2009-03-30 15:28:49 +0530586 /*
587 * The hardware is not ready/present, don't
588 * touch anything. Note this can happen early
589 * on if the IRQ is shared.
590 */
591 if (sc->sc_flags & SC_OP_INVALID)
592 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530593
Sujithff37e332008-11-24 12:07:55 +0530594
Sujith063d8be2009-03-30 15:28:49 +0530595 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530596
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400597 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530598 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530599
Sujith063d8be2009-03-30 15:28:49 +0530600 /*
601 * Figure out the reason(s) for the interrupt. Note
602 * that the hal returns a pseudo-ISR that may include
603 * bits we haven't explicitly enabled so we mask the
604 * value to insure we only process bits we requested.
605 */
606 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
607 status &= sc->imask; /* discard unasked-for bits */
608
609 /*
610 * If there are no status bits set, then this interrupt was not
611 * for me (should have been caught above).
612 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400613 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530614 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530615
616 /* Cache the status */
617 sc->intrstatus = status;
618
619 if (status & SCHED_INTR)
620 sched = true;
621
622 /*
623 * If a FATAL or RXORN interrupt is received, we have to reset the
624 * chip immediately.
625 */
626 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
627 goto chip_reset;
628
629 if (status & ATH9K_INT_SWBA)
630 tasklet_schedule(&sc->bcon_tasklet);
631
632 if (status & ATH9K_INT_TXURN)
633 ath9k_hw_updatetxtriglevel(ah, true);
634
635 if (status & ATH9K_INT_MIB) {
636 /*
637 * Disable interrupts until we service the MIB
638 * interrupt; otherwise it will continue to
639 * fire.
640 */
641 ath9k_hw_set_interrupts(ah, 0);
642 /*
643 * Let the hal handle the event. We assume
644 * it will clear whatever condition caused
645 * the interrupt.
646 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530647 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530648 ath9k_hw_set_interrupts(ah, sc->imask);
649 }
650
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400651 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
652 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530653 /* Clear RxAbort bit so that we can
654 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700655 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400656 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith063d8be2009-03-30 15:28:49 +0530657 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
658 }
Sujith063d8be2009-03-30 15:28:49 +0530659
660chip_reset:
661
Sujith817e11d2008-12-07 21:42:44 +0530662 ath_debug_stat_interrupt(sc, status);
663
Sujithff37e332008-11-24 12:07:55 +0530664 if (sched) {
665 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530666 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530667 tasklet_schedule(&sc->intr_tq);
668 }
669
670 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530671
672#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530673}
674
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700675static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530676 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530677 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700678{
679 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700680
681 switch (chan->band) {
682 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530683 switch(channel_type) {
684 case NL80211_CHAN_NO_HT:
685 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700686 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530687 break;
688 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700689 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530690 break;
691 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700692 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530693 break;
694 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695 break;
696 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530697 switch(channel_type) {
698 case NL80211_CHAN_NO_HT:
699 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700700 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530701 break;
702 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700703 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530704 break;
705 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700706 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530707 break;
708 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700709 break;
710 default:
711 break;
712 }
713
714 return chanmode;
715}
716
Jouni Malinen6ace2892008-12-17 13:32:17 +0200717static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200718 struct ath9k_keyval *hk, const u8 *addr,
719 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200721 const u8 *key_rxmic;
722 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723
Jouni Malinen6ace2892008-12-17 13:32:17 +0200724 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
725 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700726
727 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200728 /*
729 * Group key installation - only two key cache entries are used
730 * regardless of splitmic capability since group key is only
731 * used either for TX or RX.
732 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200733 if (authenticator) {
734 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
735 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
736 } else {
737 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
738 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
739 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200740 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741 }
Sujith17d79042009-02-09 13:27:03 +0530742 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200743 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700744 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
745 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200746 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700747 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200748
749 /* Separate key cache entries for TX and RX */
750
751 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700752 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200753 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
754 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700755 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530756 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700757 return 0;
758 }
759
760 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
761 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200762 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200763}
764
765static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
766{
767 int i;
768
Sujith17d79042009-02-09 13:27:03 +0530769 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
770 if (test_bit(i, sc->keymap) ||
771 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200772 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530773 if (sc->splitmic &&
774 (test_bit(i + 32, sc->keymap) ||
775 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200776 continue; /* At least one part of TKIP key allocated */
777
778 /* Found a free slot for a TKIP key */
779 return i;
780 }
781 return -1;
782}
783
784static int ath_reserve_key_cache_slot(struct ath_softc *sc)
785{
786 int i;
787
788 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530789 if (sc->splitmic) {
790 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
791 if (!test_bit(i, sc->keymap) &&
792 (test_bit(i + 32, sc->keymap) ||
793 test_bit(i + 64, sc->keymap) ||
794 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200795 return i;
Sujith17d79042009-02-09 13:27:03 +0530796 if (!test_bit(i + 32, sc->keymap) &&
797 (test_bit(i, sc->keymap) ||
798 test_bit(i + 64, sc->keymap) ||
799 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200800 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530801 if (!test_bit(i + 64, sc->keymap) &&
802 (test_bit(i , sc->keymap) ||
803 test_bit(i + 32, sc->keymap) ||
804 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200805 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530806 if (!test_bit(i + 64 + 32, sc->keymap) &&
807 (test_bit(i, sc->keymap) ||
808 test_bit(i + 32, sc->keymap) ||
809 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200810 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200811 }
812 } else {
Sujith17d79042009-02-09 13:27:03 +0530813 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
814 if (!test_bit(i, sc->keymap) &&
815 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200816 return i;
Sujith17d79042009-02-09 13:27:03 +0530817 if (test_bit(i, sc->keymap) &&
818 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200819 return i + 64;
820 }
821 }
822
823 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530824 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200825 /* Do not allow slots that could be needed for TKIP group keys
826 * to be used. This limitation could be removed if we know that
827 * TKIP will not be used. */
828 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
829 continue;
Sujith17d79042009-02-09 13:27:03 +0530830 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200831 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
832 continue;
833 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
834 continue;
835 }
836
Sujith17d79042009-02-09 13:27:03 +0530837 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200838 return i; /* Found a free slot for a key */
839 }
840
841 /* No free slot found */
842 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700843}
844
845static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200846 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100847 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700848 struct ieee80211_key_conf *key)
849{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700850 struct ath9k_keyval hk;
851 const u8 *mac = NULL;
852 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200853 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700854
855 memset(&hk, 0, sizeof(hk));
856
857 switch (key->alg) {
858 case ALG_WEP:
859 hk.kv_type = ATH9K_CIPHER_WEP;
860 break;
861 case ALG_TKIP:
862 hk.kv_type = ATH9K_CIPHER_TKIP;
863 break;
864 case ALG_CCMP:
865 hk.kv_type = ATH9K_CIPHER_AES_CCM;
866 break;
867 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200868 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869 }
870
Jouni Malinen6ace2892008-12-17 13:32:17 +0200871 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872 memcpy(hk.kv_val, key->key, key->keylen);
873
Jouni Malinen6ace2892008-12-17 13:32:17 +0200874 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
875 /* For now, use the default keys for broadcast keys. This may
876 * need to change with virtual interfaces. */
877 idx = key->keyidx;
878 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100879 if (WARN_ON(!sta))
880 return -EOPNOTSUPP;
881 mac = sta->addr;
882
Jouni Malinen6ace2892008-12-17 13:32:17 +0200883 if (vif->type != NL80211_IFTYPE_AP) {
884 /* Only keyidx 0 should be used with unicast key, but
885 * allow this for client mode for now. */
886 idx = key->keyidx;
887 } else
888 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700889 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100890 if (WARN_ON(!sta))
891 return -EOPNOTSUPP;
892 mac = sta->addr;
893
Jouni Malinen6ace2892008-12-17 13:32:17 +0200894 if (key->alg == ALG_TKIP)
895 idx = ath_reserve_key_cache_slot_tkip(sc);
896 else
897 idx = ath_reserve_key_cache_slot(sc);
898 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200899 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700900 }
901
902 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200903 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
904 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700905 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200906 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700907
908 if (!ret)
909 return -EIO;
910
Sujith17d79042009-02-09 13:27:03 +0530911 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200912 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530913 set_bit(idx + 64, sc->keymap);
914 if (sc->splitmic) {
915 set_bit(idx + 32, sc->keymap);
916 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200917 }
918 }
919
920 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700921}
922
923static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
924{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200925 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
926 if (key->hw_key_idx < IEEE80211_WEP_NKID)
927 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700928
Sujith17d79042009-02-09 13:27:03 +0530929 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200930 if (key->alg != ALG_TKIP)
931 return;
932
Sujith17d79042009-02-09 13:27:03 +0530933 clear_bit(key->hw_key_idx + 64, sc->keymap);
934 if (sc->splitmic) {
935 clear_bit(key->hw_key_idx + 32, sc->keymap);
936 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200937 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700938}
939
Sujitheb2599c2009-01-23 11:20:44 +0530940static void setup_ht_cap(struct ath_softc *sc,
941 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700942{
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530943 u8 tx_streams, rx_streams;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700944
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200945 ht_info->ht_supported = true;
946 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
947 IEEE80211_HT_CAP_SM_PS |
948 IEEE80211_HT_CAP_SGI_40 |
949 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700950
Sujith9e98ac62009-07-23 15:32:34 +0530951 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
952 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530953
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200954 /* set up supported mcs set */
955 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530956 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
957 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
Sujitheb2599c2009-01-23 11:20:44 +0530958
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530959 if (tx_streams != rx_streams) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700960 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530961 tx_streams, rx_streams);
962 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
963 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
964 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
Sujitheb2599c2009-01-23 11:20:44 +0530965 }
966
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530967 ht_info->mcs.rx_mask[0] = 0xff;
968 if (rx_streams >= 2)
969 ht_info->mcs.rx_mask[1] = 0xff;
970
971 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700972}
973
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530974static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530975 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530976 struct ieee80211_bss_conf *bss_conf)
977{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700978 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700979 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530980
981 if (bss_conf->assoc) {
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700982 DPRINTF(ah, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700983 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530984
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530985 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700986 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700987 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300988
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530989 /*
990 * Request a re-configuration of Beacon related timers
991 * on the receipt of the first Beacon frame (i.e.,
992 * after time sync with the AP).
993 */
994 sc->sc_flags |= SC_OP_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530995
996 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200997 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530998
999 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +05301000 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301001
Sujith415f7382009-04-13 21:56:46 +05301002 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301003 } else {
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001004 DPRINTF(ah, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001005 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05301006 /* Stop ANI */
1007 del_timer_sync(&sc->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301008 }
1009}
1010
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301011/********************************/
1012/* LED functions */
1013/********************************/
1014
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301015static void ath_led_blink_work(struct work_struct *work)
1016{
1017 struct ath_softc *sc = container_of(work, struct ath_softc,
1018 ath_led_blink_work.work);
1019
1020 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
1021 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301022
1023 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
1024 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301025 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301026 else
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301027 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301028 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301029
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001030 ieee80211_queue_delayed_work(sc->hw,
1031 &sc->ath_led_blink_work,
1032 (sc->sc_flags & SC_OP_LED_ON) ?
1033 msecs_to_jiffies(sc->led_off_duration) :
1034 msecs_to_jiffies(sc->led_on_duration));
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301035
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301036 sc->led_on_duration = sc->led_on_cnt ?
1037 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
1038 ATH_LED_ON_DURATION_IDLE;
1039 sc->led_off_duration = sc->led_off_cnt ?
1040 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
1041 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301042 sc->led_on_cnt = sc->led_off_cnt = 0;
1043 if (sc->sc_flags & SC_OP_LED_ON)
1044 sc->sc_flags &= ~SC_OP_LED_ON;
1045 else
1046 sc->sc_flags |= SC_OP_LED_ON;
1047}
1048
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301049static void ath_led_brightness(struct led_classdev *led_cdev,
1050 enum led_brightness brightness)
1051{
1052 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1053 struct ath_softc *sc = led->sc;
1054
1055 switch (brightness) {
1056 case LED_OFF:
1057 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301058 led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301059 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301060 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301061 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301062 if (led->led_type == ATH_LED_RADIO)
1063 sc->sc_flags &= ~SC_OP_LED_ON;
1064 } else {
1065 sc->led_off_cnt++;
1066 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301067 break;
1068 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301069 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301070 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001071 ieee80211_queue_delayed_work(sc->hw,
1072 &sc->ath_led_blink_work, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301073 } else if (led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301074 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301075 sc->sc_flags |= SC_OP_LED_ON;
1076 } else {
1077 sc->led_on_cnt++;
1078 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301079 break;
1080 default:
1081 break;
1082 }
1083}
1084
1085static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1086 char *trigger)
1087{
1088 int ret;
1089
1090 led->sc = sc;
1091 led->led_cdev.name = led->name;
1092 led->led_cdev.default_trigger = trigger;
1093 led->led_cdev.brightness_set = ath_led_brightness;
1094
1095 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1096 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001097 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301098 "Failed to register led:%s", led->name);
1099 else
1100 led->registered = 1;
1101 return ret;
1102}
1103
1104static void ath_unregister_led(struct ath_led *led)
1105{
1106 if (led->registered) {
1107 led_classdev_unregister(&led->led_cdev);
1108 led->registered = 0;
1109 }
1110}
1111
1112static void ath_deinit_leds(struct ath_softc *sc)
1113{
1114 ath_unregister_led(&sc->assoc_led);
1115 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1116 ath_unregister_led(&sc->tx_led);
1117 ath_unregister_led(&sc->rx_led);
1118 ath_unregister_led(&sc->radio_led);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301119 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301120}
1121
1122static void ath_init_leds(struct ath_softc *sc)
1123{
1124 char *trigger;
1125 int ret;
1126
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301127 if (AR_SREV_9287(sc->sc_ah))
1128 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1129 else
1130 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1131
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301132 /* Configure gpio 1 for output */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301133 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301134 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1135 /* LED off, active low */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301136 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301137
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301138 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1139
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301140 trigger = ieee80211_get_radio_led_name(sc->hw);
1141 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001142 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301143 ret = ath_register_led(sc, &sc->radio_led, trigger);
1144 sc->radio_led.led_type = ATH_LED_RADIO;
1145 if (ret)
1146 goto fail;
1147
1148 trigger = ieee80211_get_assoc_led_name(sc->hw);
1149 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001150 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301151 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1152 sc->assoc_led.led_type = ATH_LED_ASSOC;
1153 if (ret)
1154 goto fail;
1155
1156 trigger = ieee80211_get_tx_led_name(sc->hw);
1157 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001158 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301159 ret = ath_register_led(sc, &sc->tx_led, trigger);
1160 sc->tx_led.led_type = ATH_LED_TX;
1161 if (ret)
1162 goto fail;
1163
1164 trigger = ieee80211_get_rx_led_name(sc->hw);
1165 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001166 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301167 ret = ath_register_led(sc, &sc->rx_led, trigger);
1168 sc->rx_led.led_type = ATH_LED_RX;
1169 if (ret)
1170 goto fail;
1171
1172 return;
1173
1174fail:
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001175 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301176 ath_deinit_leds(sc);
1177}
1178
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001179void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301180{
Sujithcbe61d82009-02-09 13:27:12 +05301181 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001182 struct ieee80211_channel *channel = sc->hw->conf.channel;
1183 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301184
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301185 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301186 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +05301187
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301188 if (!ah->curchan)
1189 ah->curchan = ath_get_curchannel(sc, sc->hw);
1190
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301191 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301192 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001193 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001194 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001195 "Unable to reset channel %u (%uMhz) ",
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301196 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001197 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301198 }
1199 spin_unlock_bh(&sc->sc_resetlock);
1200
1201 ath_update_txpow(sc);
1202 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001203 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301204 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301205 return;
1206 }
1207
1208 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001209 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301210
1211 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301212 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301213
1214 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301215 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301216 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301217 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301218
1219 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301220 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301221}
1222
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001223void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301224{
Sujithcbe61d82009-02-09 13:27:12 +05301225 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001226 struct ieee80211_channel *channel = sc->hw->conf.channel;
1227 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301228
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301229 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301230 ieee80211_stop_queues(sc->hw);
1231
1232 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301233 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1234 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301235
1236 /* Disable interrupts */
1237 ath9k_hw_set_interrupts(ah, 0);
1238
Sujith043a0402009-01-16 21:38:47 +05301239 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301240 ath_stoprecv(sc); /* turn off frame recv */
1241 ath_flushrecv(sc); /* flush recv queue */
1242
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301243 if (!ah->curchan)
1244 ah->curchan = ath_get_curchannel(sc, sc->hw);
1245
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301246 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301247 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001248 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001249 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301250 "Unable to reset channel %u (%uMhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301251 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001252 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301253 }
1254 spin_unlock_bh(&sc->sc_resetlock);
1255
1256 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301257 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301258 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001259 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301260}
1261
Gabor Juhos5077fd32009-03-06 11:17:55 +01001262/*******************/
1263/* Rfkill */
1264/*******************/
1265
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301266static bool ath_is_rfkill_set(struct ath_softc *sc)
1267{
Sujithcbe61d82009-02-09 13:27:12 +05301268 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301269
Sujith2660b812009-02-09 13:27:26 +05301270 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1271 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301272}
1273
Johannes Berg3b319aa2009-06-13 14:50:26 +05301274static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301275{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301276 struct ath_wiphy *aphy = hw->priv;
1277 struct ath_softc *sc = aphy->sc;
1278 bool blocked = !!ath_is_rfkill_set(sc);
1279
1280 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
Johannes Berg19d337d2009-06-02 13:01:37 +02001281}
1282
Johannes Berg3b319aa2009-06-13 14:50:26 +05301283static void ath_start_rfkill_poll(struct ath_softc *sc)
Johannes Berg19d337d2009-06-02 13:01:37 +02001284{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301285 struct ath_hw *ah = sc->sc_ah;
Johannes Berg19d337d2009-06-02 13:01:37 +02001286
Johannes Berg3b319aa2009-06-13 14:50:26 +05301287 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1288 wiphy_rfkill_start_polling(sc->hw->wiphy);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301289}
1290
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001291void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001292{
1293 ath_detach(sc);
1294 free_irq(sc->irq, sc);
1295 ath_bus_cleanup(sc);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001296 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001297 ieee80211_free_hw(sc->hw);
1298}
1299
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001300void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301301{
1302 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001303 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05301304 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301305
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301306 ath9k_ps_wakeup(sc);
1307
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001308 dev_dbg(sc->dev, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301309
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001310 ath_deinit_leds(sc);
Sujithe31f7b92009-09-23 13:49:12 +05301311 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001312
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001313 for (i = 0; i < sc->num_sec_wiphy; i++) {
1314 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1315 if (aphy == NULL)
1316 continue;
1317 sc->sec_wiphy[i] = NULL;
1318 ieee80211_unregister_hw(aphy->hw);
1319 ieee80211_free_hw(aphy->hw);
1320 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301321 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301322 ath_rx_cleanup(sc);
1323 ath_tx_cleanup(sc);
1324
Sujith9c84b792008-10-29 10:17:13 +05301325 tasklet_kill(&sc->intr_tq);
1326 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301327
Sujith9c84b792008-10-29 10:17:13 +05301328 if (!(sc->sc_flags & SC_OP_INVALID))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001329 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301330
Sujith9c84b792008-10-29 10:17:13 +05301331 /* cleanup tx queues */
1332 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1333 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301334 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301335
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001336 if ((sc->btcoex.no_stomp_timer) &&
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001337 ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001338 ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301339
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001340 ath9k_hw_detach(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001341 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001342 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301343}
1344
Bob Copelande3bb2492009-03-30 22:30:30 -04001345static int ath9k_reg_notifier(struct wiphy *wiphy,
1346 struct regulatory_request *request)
1347{
1348 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1349 struct ath_wiphy *aphy = hw->priv;
1350 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001351 struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
Bob Copelande3bb2492009-03-30 22:30:30 -04001352
1353 return ath_reg_notifier_apply(wiphy, request, reg);
1354}
1355
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001356/*
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001357 * Detects if there is any priority bt traffic
1358 */
1359static void ath_detect_bt_priority(struct ath_softc *sc)
1360{
1361 struct ath_btcoex *btcoex = &sc->btcoex;
1362 struct ath_hw *ah = sc->sc_ah;
1363
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001364 if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001365 btcoex->bt_priority_cnt++;
1366
1367 if (time_after(jiffies, btcoex->bt_priority_time +
1368 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
1369 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
1370 DPRINTF(sc->sc_ah, ATH_DBG_BTCOEX,
1371 "BT priority traffic detected");
1372 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1373 } else {
1374 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
1375 }
1376
1377 btcoex->bt_priority_cnt = 0;
1378 btcoex->bt_priority_time = jiffies;
1379 }
1380}
1381
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001382/*
1383 * Configures appropriate weight based on stomp type.
1384 */
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001385static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
1386 enum ath_stomp_type stomp_type)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001387{
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001388 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001389
1390 switch (stomp_type) {
1391 case ATH_BTCOEX_STOMP_ALL:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001392 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1393 AR_STOMP_ALL_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001394 break;
1395 case ATH_BTCOEX_STOMP_LOW:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001396 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1397 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001398 break;
1399 case ATH_BTCOEX_STOMP_NONE:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001400 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1401 AR_STOMP_NONE_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001402 break;
1403 default:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001404 DPRINTF(ah, ATH_DBG_BTCOEX, "Invalid Stomptype\n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001405 break;
1406 }
1407
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001408 ath9k_hw_btcoex_enable(ah);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001409}
1410
1411/*
1412 * This is the master bt coex timer which runs for every
1413 * 45ms, bt traffic will be given priority during 55% of this
1414 * period while wlan gets remaining 45%
1415 */
1416static void ath_btcoex_period_timer(unsigned long data)
1417{
1418 struct ath_softc *sc = (struct ath_softc *) data;
1419 struct ath_hw *ah = sc->sc_ah;
1420 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001421
1422 ath_detect_bt_priority(sc);
1423
1424 spin_lock_bh(&btcoex->btcoex_lock);
1425
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001426 ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001427
1428 spin_unlock_bh(&btcoex->btcoex_lock);
1429
1430 if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1431 if (btcoex->hw_timer_enabled)
1432 ath_gen_timer_stop(ah, btcoex->no_stomp_timer);
1433
1434 ath_gen_timer_start(ah,
1435 btcoex->no_stomp_timer,
1436 (ath9k_hw_gettsf32(ah) +
1437 btcoex->btcoex_no_stomp),
1438 btcoex->btcoex_no_stomp * 10);
1439 btcoex->hw_timer_enabled = true;
1440 }
1441
1442 mod_timer(&btcoex->period_timer, jiffies +
1443 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
1444}
1445
1446/*
1447 * Generic tsf based hw timer which configures weight
1448 * registers to time slice between wlan and bt traffic
1449 */
1450static void ath_btcoex_no_stomp_timer(void *arg)
1451{
1452 struct ath_softc *sc = (struct ath_softc *)arg;
1453 struct ath_hw *ah = sc->sc_ah;
1454 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001455
1456 DPRINTF(ah, ATH_DBG_BTCOEX, "no stomp timer running \n");
1457
1458 spin_lock_bh(&btcoex->btcoex_lock);
1459
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001460 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001461 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001462 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001463 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001464
1465 spin_unlock_bh(&btcoex->btcoex_lock);
1466}
1467
1468static int ath_init_btcoex_timer(struct ath_softc *sc)
1469{
1470 struct ath_btcoex *btcoex = &sc->btcoex;
1471
1472 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
1473 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
1474 btcoex->btcoex_period / 100;
1475
1476 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
1477 (unsigned long) sc);
1478
1479 spin_lock_init(&btcoex->btcoex_lock);
1480
1481 btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
1482 ath_btcoex_no_stomp_timer,
1483 ath_btcoex_no_stomp_timer,
1484 (void *) sc, AR_FIRST_NDP_TIMER);
1485
1486 if (!btcoex->no_stomp_timer)
1487 return -ENOMEM;
1488
1489 return 0;
1490}
1491
1492/*
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001493 * Read and write, they both share the same lock. We do this to serialize
1494 * reads and writes on Atheros 802.11n PCI devices only. This is required
1495 * as the FIFO on these devices can only accept sanely 2 requests. After
1496 * that the device goes bananas. Serializing the reads/writes prevents this
1497 * from happening.
1498 */
1499
1500static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
1501{
1502 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1503
1504 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1505 unsigned long flags;
1506 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1507 iowrite32(val, ah->ah_sc->mem + reg_offset);
1508 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1509 } else
1510 iowrite32(val, ah->ah_sc->mem + reg_offset);
1511}
1512
1513static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
1514{
1515 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1516 u32 val;
1517
1518 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1519 unsigned long flags;
1520 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1521 val = ioread32(ah->ah_sc->mem + reg_offset);
1522 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1523 } else
1524 val = ioread32(ah->ah_sc->mem + reg_offset);
1525 return val;
1526}
1527
1528static struct ath_ops ath9k_common_ops = {
1529 .read = ath9k_ioread32,
1530 .write = ath9k_iowrite32,
1531};
1532
1533/*
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001534 * Initialize and fill ath_softc, ath_sofct is the
1535 * "Software Carrier" struct. Historically it has existed
1536 * to allow the separation between hardware specific
1537 * variables (now in ath_hw) and driver specific variables.
1538 */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301539static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
Sujithff37e332008-11-24 12:07:55 +05301540{
Sujithcbe61d82009-02-09 13:27:12 +05301541 struct ath_hw *ah = NULL;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001542 struct ath_common *common;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001543 int r = 0, i;
Sujithff37e332008-11-24 12:07:55 +05301544 int csz = 0;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001545 int qnum;
Sujithff37e332008-11-24 12:07:55 +05301546
1547 /* XXX: hardware will not be ready until ath_open() being called */
1548 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301549
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001550 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301551 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001552 spin_lock_init(&sc->sc_serial_rw);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05301553 spin_lock_init(&sc->ani_lock);
Gabor Juhos04717cc2009-07-14 20:17:13 -04001554 spin_lock_init(&sc->sc_pm_lock);
Sujithaa33de02008-12-18 11:40:16 +05301555 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301556 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301557 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301558 (unsigned long)sc);
1559
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001560 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1561 if (!ah) {
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001562 r = -ENOMEM;
1563 goto bad_no_ah;
1564 }
1565
1566 ah->ah_sc = sc;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -07001567 ah->hw_version.devid = devid;
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301568 ah->hw_version.subsysid = subsysid;
Luis R. Rodrigueze1e2f932009-08-03 12:24:38 -07001569 sc->sc_ah = ah;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001570
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001571 common = ath9k_hw_common(ah);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001572 common->ops = &ath9k_common_ops;
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001573 common->ah = ah;
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -07001574 common->hw = sc->hw;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001575
1576 /*
1577 * Cache line size is used to size and align various
1578 * structures used to communicate with the hardware.
1579 */
1580 ath_read_cachesize(sc, &csz);
1581 /* XXX assert csz is non-zero */
1582 common->cachelsz = csz << 2; /* convert to bytes */
1583
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001584 if (ath9k_init_debug(ah) < 0)
1585 dev_err(sc->dev, "Unable to create debugfs files\n");
1586
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001587 r = ath9k_hw_init(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001588 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001589 DPRINTF(ah, ATH_DBG_FATAL,
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001590 "Unable to initialize hardware; "
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001591 "initialization status: %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301592 goto bad;
1593 }
Sujithff37e332008-11-24 12:07:55 +05301594
1595 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301596 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301597 if (sc->keymax > ATH_KEYMAX) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001598 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05301599 "Warning, using only %u entries in %u key cache\n",
Sujith17d79042009-02-09 13:27:03 +05301600 ATH_KEYMAX, sc->keymax);
1601 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301602 }
1603
1604 /*
1605 * Reset the key cache since some parts do not
1606 * reset the contents on initial power up.
1607 */
Sujith17d79042009-02-09 13:27:03 +05301608 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301609 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301610
Sujithff37e332008-11-24 12:07:55 +05301611 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301612 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001613
Sujithff37e332008-11-24 12:07:55 +05301614 /* Setup rate tables */
1615
1616 ath_rate_attach(sc);
1617 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1618 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1619
1620 /*
1621 * Allocate hardware transmit queues: one queue for
1622 * beacon frames and one data queue for each QoS
1623 * priority. Note that the hal handles reseting
1624 * these queues at the needed time.
1625 */
Sujithb77f4832008-12-07 21:44:03 +05301626 sc->beacon.beaconq = ath_beaconq_setup(ah);
1627 if (sc->beacon.beaconq == -1) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001628 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301629 "Unable to setup a beacon xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001630 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301631 goto bad2;
1632 }
Sujithb77f4832008-12-07 21:44:03 +05301633 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1634 if (sc->beacon.cabq == NULL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001635 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301636 "Unable to setup CAB xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001637 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301638 goto bad2;
1639 }
1640
Sujith17d79042009-02-09 13:27:03 +05301641 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301642 ath_cabq_update(sc);
1643
Sujithb77f4832008-12-07 21:44:03 +05301644 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1645 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301646
1647 /* Setup data queues */
1648 /* NB: ensure BK queue is the lowest priority h/w queue */
1649 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001650 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301651 "Unable to setup xmit queue for BK traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001652 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301653 goto bad2;
1654 }
1655
1656 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001657 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301658 "Unable to setup xmit queue for BE traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001659 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301660 goto bad2;
1661 }
1662 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001663 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301664 "Unable to setup xmit queue for VI traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001665 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301666 goto bad2;
1667 }
1668 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001669 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301670 "Unable to setup xmit queue for VO traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001671 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301672 goto bad2;
1673 }
1674
1675 /* Initializes the noise floor to a reasonable default value.
1676 * Later on this will be updated during ANI processing. */
1677
Sujith17d79042009-02-09 13:27:03 +05301678 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1679 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301680
1681 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1682 ATH9K_CIPHER_TKIP, NULL)) {
1683 /*
1684 * Whether we should enable h/w TKIP MIC.
1685 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1686 * report WMM capable, so it's always safe to turn on
1687 * TKIP MIC in this case.
1688 */
1689 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1690 0, 1, NULL);
1691 }
1692
1693 /*
1694 * Check whether the separate key cache entries
1695 * are required to handle both tx+rx MIC keys.
1696 * With split mic keys the number of stations is limited
1697 * to 27 otherwise 59.
1698 */
1699 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1700 ATH9K_CIPHER_TKIP, NULL)
1701 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1702 ATH9K_CIPHER_MIC, NULL)
1703 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1704 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301705 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301706
1707 /* turn on mcast key search if possible */
1708 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1709 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1710 1, NULL);
1711
Sujith17d79042009-02-09 13:27:03 +05301712 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301713
1714 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301715 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301716 sc->sc_flags |= SC_OP_TXAGGR;
1717 sc->sc_flags |= SC_OP_RXAGGR;
1718 }
1719
Sujith2660b812009-02-09 13:27:26 +05301720 sc->tx_chainmask = ah->caps.tx_chainmask;
1721 sc->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301722
1723 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301724 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301725
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001726 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001727 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301728
Sujithb77f4832008-12-07 21:44:03 +05301729 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301730
1731 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001732 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001733 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001734 sc->beacon.bslot_aphy[i] = NULL;
1735 }
Sujithff37e332008-11-24 12:07:55 +05301736
Sujithff37e332008-11-24 12:07:55 +05301737 /* setup channels and rates */
1738
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001739 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301740 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1741 sc->rates[IEEE80211_BAND_2GHZ];
1742 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001743 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1744 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301745
Sujith2660b812009-02-09 13:27:26 +05301746 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001747 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301748 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1749 sc->rates[IEEE80211_BAND_5GHZ];
1750 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001751 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1752 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301753 }
1754
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001755 switch (ah->btcoex_hw.scheme) {
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001756 case ATH_BTCOEX_CFG_NONE:
1757 break;
1758 case ATH_BTCOEX_CFG_2WIRE:
1759 ath9k_hw_btcoex_init_2wire(ah);
1760 break;
1761 case ATH_BTCOEX_CFG_3WIRE:
1762 ath9k_hw_btcoex_init_3wire(ah);
1763 r = ath_init_btcoex_timer(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301764 if (r)
1765 goto bad2;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001766 qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001767 ath9k_hw_init_btcoex_hw(ah, qnum);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001768 sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001769 break;
1770 default:
1771 WARN_ON(1);
1772 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301773 }
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301774
Sujithff37e332008-11-24 12:07:55 +05301775 return 0;
1776bad2:
1777 /* cleanup tx queues */
1778 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1779 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301780 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301781bad:
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001782 ath9k_hw_detach(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001783bad_no_ah:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001784 ath9k_exit_debug(sc->sc_ah);
1785 sc->sc_ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301786
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001787 return r;
Sujithff37e332008-11-24 12:07:55 +05301788}
1789
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001790void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301791{
Sujith9c84b792008-10-29 10:17:13 +05301792 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1793 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1794 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301795 IEEE80211_HW_AMPDU_AGGREGATION |
1796 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301797 IEEE80211_HW_PS_NULLFUNC_STACK |
1798 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301799
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001800 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001801 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1802
Sujith9c84b792008-10-29 10:17:13 +05301803 hw->wiphy->interface_modes =
1804 BIT(NL80211_IFTYPE_AP) |
1805 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001806 BIT(NL80211_IFTYPE_ADHOC) |
1807 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301808
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301809 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301810 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301811 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001812 hw->max_listen_interval = 10;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001813 /* Hardware supports 10 but we use 4 */
1814 hw->max_rate_tries = 4;
Sujith528f0c62008-10-29 10:14:26 +05301815 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301816 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301817
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301818 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301819
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001820 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1821 &sc->sbands[IEEE80211_BAND_2GHZ];
1822 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1823 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1824 &sc->sbands[IEEE80211_BAND_5GHZ];
1825}
1826
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001827/* Device driver core initialization */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301828int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001829{
1830 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001831 struct ath_common *common;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001832 struct ath_hw *ah;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001833 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001834 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001835
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001836 dev_dbg(sc->dev, "Attach ATH hw\n");
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001837
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301838 error = ath_init_softc(devid, sc, subsysid);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001839 if (error != 0)
1840 return error;
1841
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001842 ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001843 common = ath9k_hw_common(ah);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001844
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001845 /* get mac address from hardware and set in mac80211 */
1846
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001847 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001848
1849 ath_set_hw_capab(sc, hw);
1850
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001851 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001852 ath9k_reg_notifier);
1853 if (error)
1854 return error;
1855
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001856 reg = &common->regulatory;
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001857
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001858 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301859 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001860 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301861 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301862 }
1863
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301864 /* initialize tx/rx engine */
1865 error = ath_tx_init(sc, ATH_TXBUF);
1866 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301867 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301868
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301869 error = ath_rx_init(sc, ATH_RXBUF);
1870 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301871 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301872
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001873 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001874 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1875 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001876
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301877 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301878
Bob Copeland3a702e42009-03-30 22:30:29 -04001879 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001880 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001881 if (error)
1882 goto error_attach;
1883 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001884
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301885 /* Initialize LED control */
1886 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301887
Johannes Berg3b319aa2009-06-13 14:50:26 +05301888 ath_start_rfkill_poll(sc);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001889
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301890 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301891
1892error_attach:
1893 /* cleanup tx queues */
1894 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1895 if (ATH_TXQ_SETUP(sc, i))
1896 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1897
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001898 ath9k_hw_detach(ah);
1899 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001900 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301901
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301902 return error;
1903}
1904
Sujithff37e332008-11-24 12:07:55 +05301905int ath_reset(struct ath_softc *sc, bool retry_tx)
1906{
Sujithcbe61d82009-02-09 13:27:12 +05301907 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001908 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001909 int r;
Sujithff37e332008-11-24 12:07:55 +05301910
1911 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301912 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301913 ath_stoprecv(sc);
1914 ath_flushrecv(sc);
1915
1916 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301917 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001918 if (r)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001919 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301920 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301921 spin_unlock_bh(&sc->sc_resetlock);
1922
1923 if (ath_startrecv(sc) != 0)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001924 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301925
1926 /*
1927 * We may be doing a reset in response to a request
1928 * that changes the channel so update any state that
1929 * might change as a result.
1930 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001931 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301932
1933 ath_update_txpow(sc);
1934
1935 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001936 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301937
Sujith17d79042009-02-09 13:27:03 +05301938 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301939
1940 if (retry_tx) {
1941 int i;
1942 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1943 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301944 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1945 ath_txq_schedule(sc, &sc->tx.txq[i]);
1946 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301947 }
1948 }
1949 }
1950
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001951 return r;
Sujithff37e332008-11-24 12:07:55 +05301952}
1953
1954/*
1955 * This function will allocate both the DMA descriptor structure, and the
1956 * buffers it contains. These are used to contain the descriptors used
1957 * by the system.
1958*/
1959int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1960 struct list_head *head, const char *name,
1961 int nbuf, int ndesc)
1962{
1963#define DS2PHYS(_dd, _ds) \
1964 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1965#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1966#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1967
1968 struct ath_desc *ds;
1969 struct ath_buf *bf;
1970 int i, bsize, error;
1971
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001972 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Sujith04bd46382008-11-28 22:18:05 +05301973 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05301974
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05301975 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05301976 /* ath_desc must be a multiple of DWORDs */
1977 if ((sizeof(struct ath_desc) % 4) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001978 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
Sujithff37e332008-11-24 12:07:55 +05301979 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1980 error = -ENOMEM;
1981 goto fail;
1982 }
1983
Sujithff37e332008-11-24 12:07:55 +05301984 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1985
1986 /*
1987 * Need additional DMA memory because we can't use
1988 * descriptors that cross the 4K page boundary. Assume
1989 * one skipped descriptor per 4K page.
1990 */
Sujith2660b812009-02-09 13:27:26 +05301991 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05301992 u32 ndesc_skipped =
1993 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1994 u32 dma_len;
1995
1996 while (ndesc_skipped) {
1997 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1998 dd->dd_desc_len += dma_len;
1999
2000 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
2001 };
2002 }
2003
2004 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01002005 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302006 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302007 if (dd->dd_desc == NULL) {
2008 error = -ENOMEM;
2009 goto fail;
2010 }
2011 ds = dd->dd_desc;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002012 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Sujithae459af2009-03-30 15:28:40 +05302013 name, ds, (u32) dd->dd_desc_len,
Sujithff37e332008-11-24 12:07:55 +05302014 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
2015
2016 /* allocate buffers */
2017 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302018 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302019 if (bf == NULL) {
2020 error = -ENOMEM;
2021 goto fail2;
2022 }
Sujithff37e332008-11-24 12:07:55 +05302023 dd->dd_bufptr = bf;
2024
Sujithff37e332008-11-24 12:07:55 +05302025 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
2026 bf->bf_desc = ds;
2027 bf->bf_daddr = DS2PHYS(dd, ds);
2028
Sujith2660b812009-02-09 13:27:26 +05302029 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05302030 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
2031 /*
2032 * Skip descriptor addresses which can cause 4KB
2033 * boundary crossing (addr + length) with a 32 dword
2034 * descriptor fetch.
2035 */
2036 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
2037 ASSERT((caddr_t) bf->bf_desc <
2038 ((caddr_t) dd->dd_desc +
2039 dd->dd_desc_len));
2040
2041 ds += ndesc;
2042 bf->bf_desc = ds;
2043 bf->bf_daddr = DS2PHYS(dd, ds);
2044 }
2045 }
2046 list_add_tail(&bf->list, head);
2047 }
2048 return 0;
2049fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01002050 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2051 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302052fail:
2053 memset(dd, 0, sizeof(*dd));
2054 return error;
2055#undef ATH_DESC_4KB_BOUND_CHECK
2056#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
2057#undef DS2PHYS
2058}
2059
2060void ath_descdma_cleanup(struct ath_softc *sc,
2061 struct ath_descdma *dd,
2062 struct list_head *head)
2063{
Gabor Juhos7da3c552009-01-14 20:17:03 +01002064 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2065 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302066
2067 INIT_LIST_HEAD(head);
2068 kfree(dd->dd_bufptr);
2069 memset(dd, 0, sizeof(*dd));
2070}
2071
2072int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
2073{
2074 int qnum;
2075
2076 switch (queue) {
2077 case 0:
Sujithb77f4832008-12-07 21:44:03 +05302078 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05302079 break;
2080 case 1:
Sujithb77f4832008-12-07 21:44:03 +05302081 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05302082 break;
2083 case 2:
Sujithb77f4832008-12-07 21:44:03 +05302084 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302085 break;
2086 case 3:
Sujithb77f4832008-12-07 21:44:03 +05302087 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05302088 break;
2089 default:
Sujithb77f4832008-12-07 21:44:03 +05302090 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302091 break;
2092 }
2093
2094 return qnum;
2095}
2096
2097int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
2098{
2099 int qnum;
2100
2101 switch (queue) {
2102 case ATH9K_WME_AC_VO:
2103 qnum = 0;
2104 break;
2105 case ATH9K_WME_AC_VI:
2106 qnum = 1;
2107 break;
2108 case ATH9K_WME_AC_BE:
2109 qnum = 2;
2110 break;
2111 case ATH9K_WME_AC_BK:
2112 qnum = 3;
2113 break;
2114 default:
2115 qnum = -1;
2116 break;
2117 }
2118
2119 return qnum;
2120}
2121
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002122/* XXX: Remove me once we don't depend on ath9k_channel for all
2123 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002124void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
2125 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002126{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002127 struct ieee80211_channel *chan = hw->conf.channel;
2128 struct ieee80211_conf *conf = &hw->conf;
2129
2130 ichan->channel = chan->center_freq;
2131 ichan->chan = chan;
2132
2133 if (chan->band == IEEE80211_BAND_2GHZ) {
2134 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05302135 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002136 } else {
2137 ichan->chanmode = CHANNEL_A;
2138 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
2139 }
2140
2141 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
2142
2143 if (conf_is_ht(conf)) {
2144 if (conf_is_ht40(conf))
2145 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
2146
2147 ichan->chanmode = ath_get_extchanmode(sc, chan,
2148 conf->channel_type);
2149 }
2150}
2151
Sujithff37e332008-11-24 12:07:55 +05302152/**********************/
2153/* mac80211 callbacks */
2154/**********************/
2155
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002156/*
2157 * (Re)start btcoex timers
2158 */
2159static void ath9k_btcoex_timer_resume(struct ath_softc *sc)
2160{
2161 struct ath_btcoex *btcoex = &sc->btcoex;
2162 struct ath_hw *ah = sc->sc_ah;
2163
2164 DPRINTF(ah, ATH_DBG_BTCOEX, "Starting btcoex timers");
2165
2166 /* make sure duty cycle timer is also stopped when resuming */
2167 if (btcoex->hw_timer_enabled)
2168 ath_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
2169
2170 btcoex->bt_priority_cnt = 0;
2171 btcoex->bt_priority_time = jiffies;
2172 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
2173
2174 mod_timer(&btcoex->period_timer, jiffies);
2175}
2176
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002177static int ath9k_start(struct ieee80211_hw *hw)
2178{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002179 struct ath_wiphy *aphy = hw->priv;
2180 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002181 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002182 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05302183 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302184 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002185
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002186 DPRINTF(ah, ATH_DBG_CONFIG, "Starting driver with "
Sujith04bd46382008-11-28 22:18:05 +05302187 "initial channel: %d MHz\n", curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002188
Sujith141b38b2009-02-04 08:10:07 +05302189 mutex_lock(&sc->mutex);
2190
Jouni Malinen9580a222009-03-03 19:23:33 +02002191 if (ath9k_wiphy_started(sc)) {
2192 if (sc->chan_idx == curchan->hw_value) {
2193 /*
2194 * Already on the operational channel, the new wiphy
2195 * can be marked active.
2196 */
2197 aphy->state = ATH_WIPHY_ACTIVE;
2198 ieee80211_wake_queues(hw);
2199 } else {
2200 /*
2201 * Another wiphy is on another channel, start the new
2202 * wiphy in paused state.
2203 */
2204 aphy->state = ATH_WIPHY_PAUSED;
2205 ieee80211_stop_queues(hw);
2206 }
2207 mutex_unlock(&sc->mutex);
2208 return 0;
2209 }
2210 aphy->state = ATH_WIPHY_ACTIVE;
2211
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002212 /* setup initial channel */
2213
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302214 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002215
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302216 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217
Sujithff37e332008-11-24 12:07:55 +05302218 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002219 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05302220
2221 /*
2222 * The basic interface to setting the hardware in a good
2223 * state is ``reset''. On return the hardware is known to
2224 * be powered up and with interrupts disabled. This must
2225 * be followed by initialization of the appropriate bits
2226 * and then setup of the interrupt mask.
2227 */
2228 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002229 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002230 if (r) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002231 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05302232 "Unable to reset hardware; reset status %d "
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002233 "(freq %u MHz)\n", r,
2234 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05302235 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05302236 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002237 }
Sujithff37e332008-11-24 12:07:55 +05302238 spin_unlock_bh(&sc->sc_resetlock);
2239
2240 /*
2241 * This is needed only to setup initial state
2242 * but it's best done after a reset.
2243 */
2244 ath_update_txpow(sc);
2245
2246 /*
2247 * Setup the hardware after reset:
2248 * The receive engine is set going.
2249 * Frame transmit is handled entirely
2250 * in the frame output path; there's nothing to do
2251 * here except setup the interrupt mask.
2252 */
2253 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002254 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05302255 r = -EIO;
2256 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05302257 }
2258
2259 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05302260 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05302261 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2262 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2263
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002264 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05302265 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05302266
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002267 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302268 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302269
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002270 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302271
2272 sc->sc_flags &= ~SC_OP_INVALID;
2273
2274 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302275 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002276 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302277
Jouni Malinenbce048d2009-03-03 19:23:28 +02002278 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002279
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002280 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002281
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002282 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
2283 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07002284 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
2285 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002286 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05302287
Luis R. Rodriguez867633f2009-09-10 12:12:23 -07002288 if (sc->bus_ops->bt_coex_prep)
2289 sc->bus_ops->bt_coex_prep(sc);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002290 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002291 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302292 }
2293
Sujith141b38b2009-02-04 08:10:07 +05302294mutex_unlock:
2295 mutex_unlock(&sc->mutex);
2296
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002297 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002298}
2299
2300static int ath9k_tx(struct ieee80211_hw *hw,
2301 struct sk_buff *skb)
2302{
Jouni Malinen147583c2008-08-11 14:01:50 +03002303 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002304 struct ath_wiphy *aphy = hw->priv;
2305 struct ath_softc *sc = aphy->sc;
Sujith528f0c62008-10-29 10:14:26 +05302306 struct ath_tx_control txctl;
2307 int hdrlen, padsize;
2308
Jouni Malinen8089cc42009-03-03 19:23:38 +02002309 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Jouni Malinenee166a02009-03-03 19:23:36 +02002310 printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
2311 "%d\n", wiphy_name(hw->wiphy), aphy->state);
2312 goto exit;
2313 }
2314
Gabor Juhos96148322009-07-24 17:27:21 +02002315 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03002316 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2317 /*
2318 * mac80211 does not set PM field for normal data frames, so we
2319 * need to update that based on the current PS mode.
2320 */
2321 if (ieee80211_is_data(hdr->frame_control) &&
2322 !ieee80211_is_nullfunc(hdr->frame_control) &&
2323 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002324 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Add PM=1 for a TX frame "
Jouni Malinendc8c4582009-05-19 17:01:42 +03002325 "while in PS mode\n");
2326 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2327 }
2328 }
2329
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002330 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2331 /*
2332 * We are using PS-Poll and mac80211 can request TX while in
2333 * power save mode. Need to wake up hardware for the TX to be
2334 * completed and if needed, also for RX of buffered frames.
2335 */
2336 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2337 ath9k_ps_wakeup(sc);
2338 ath9k_hw_setrxabort(sc->sc_ah, 0);
2339 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002340 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Sending PS-Poll to pick a "
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002341 "buffered frame\n");
2342 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2343 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002344 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Wake up to complete TX\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002345 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2346 }
2347 /*
2348 * The actual restore operation will happen only after
2349 * the sc_flags bit is cleared. We are just dropping
2350 * the ps_usecount here.
2351 */
2352 ath9k_ps_restore(sc);
2353 }
2354
Sujith528f0c62008-10-29 10:14:26 +05302355 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002356
2357 /*
2358 * As a temporary workaround, assign seq# here; this will likely need
2359 * to be cleaned up to work better with Beacon transmission and virtual
2360 * BSSes.
2361 */
2362 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2363 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2364 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302365 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002366 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302367 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002368 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002369
2370 /* Add the padding after the header if this is not already done */
2371 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2372 if (hdrlen & 3) {
2373 padsize = hdrlen % 4;
2374 if (skb_headroom(skb) < padsize)
2375 return -1;
2376 skb_push(skb, padsize);
2377 memmove(skb->data, skb->data + padsize, hdrlen);
2378 }
2379
Sujith528f0c62008-10-29 10:14:26 +05302380 /* Check if a tx queue is available */
2381
2382 txctl.txq = ath_test_get_txq(sc, skb);
2383 if (!txctl.txq)
2384 goto exit;
2385
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002386 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002387
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002388 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002389 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302390 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002391 }
2392
2393 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302394exit:
2395 dev_kfree_skb_any(skb);
2396 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002397}
2398
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002399/*
2400 * Pause btcoex timer and bt duty cycle timer
2401 */
2402static void ath9k_btcoex_timer_pause(struct ath_softc *sc)
2403{
2404 struct ath_btcoex *btcoex = &sc->btcoex;
2405 struct ath_hw *ah = sc->sc_ah;
2406
2407 del_timer_sync(&btcoex->period_timer);
2408
2409 if (btcoex->hw_timer_enabled)
2410 ath_gen_timer_stop(ah, btcoex->no_stomp_timer);
2411
2412 btcoex->hw_timer_enabled = false;
2413}
2414
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002415static void ath9k_stop(struct ieee80211_hw *hw)
2416{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002417 struct ath_wiphy *aphy = hw->priv;
2418 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002419 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05302420
Sujith4c483812009-08-18 10:51:52 +05302421 mutex_lock(&sc->mutex);
2422
Jouni Malinen9580a222009-03-03 19:23:33 +02002423 aphy->state = ATH_WIPHY_INACTIVE;
2424
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07002425 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2426 cancel_delayed_work_sync(&sc->tx_complete_work);
2427
2428 if (!sc->num_sec_wiphy) {
2429 cancel_delayed_work_sync(&sc->wiphy_work);
2430 cancel_work_sync(&sc->chan_work);
2431 }
2432
Sujith9c84b792008-10-29 10:17:13 +05302433 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002434 DPRINTF(ah, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05302435 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05302436 return;
2437 }
2438
Jouni Malinen9580a222009-03-03 19:23:33 +02002439 if (ath9k_wiphy_started(sc)) {
2440 mutex_unlock(&sc->mutex);
2441 return; /* another wiphy still in use */
2442 }
2443
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002444 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002445 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002446 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002447 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302448 }
2449
Sujithff37e332008-11-24 12:07:55 +05302450 /* make sure h/w will not generate any interrupt
2451 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002452 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05302453
2454 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302455 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302456 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002457 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05302458 } else
Sujithb77f4832008-12-07 21:44:03 +05302459 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302460
Sujithff37e332008-11-24 12:07:55 +05302461 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002462 ath9k_hw_disable(ah);
2463 ath9k_hw_configpcipowersave(ah, 1, 1);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002464 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05302465
2466 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467
Sujith141b38b2009-02-04 08:10:07 +05302468 mutex_unlock(&sc->mutex);
2469
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002470 DPRINTF(ah, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002471}
2472
2473static int ath9k_add_interface(struct ieee80211_hw *hw,
2474 struct ieee80211_if_init_conf *conf)
2475{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002476 struct ath_wiphy *aphy = hw->priv;
2477 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302478 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002479 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002480 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002481
Sujith141b38b2009-02-04 08:10:07 +05302482 mutex_lock(&sc->mutex);
2483
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002484 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2485 sc->nvifs > 0) {
2486 ret = -ENOBUFS;
2487 goto out;
2488 }
2489
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002490 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002491 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002492 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002493 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002494 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002495 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002496 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002497 if (sc->nbcnvifs >= ATH_BCBUF) {
2498 ret = -ENOBUFS;
2499 goto out;
2500 }
Pat Erley9cb54122009-03-20 22:59:59 -04002501 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002502 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002503 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002504 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302505 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002506 ret = -EOPNOTSUPP;
2507 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002508 }
2509
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002510 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002511
Sujith17d79042009-02-09 13:27:03 +05302512 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302513 avp->av_opmode = ic_opmode;
2514 avp->av_bslot = -1;
2515
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002516 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002517
2518 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2519 ath9k_set_bssid_mask(hw);
2520
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002521 if (sc->nvifs > 1)
2522 goto out; /* skip global settings for secondary vif */
2523
Sujithb238e902009-03-03 10:16:56 +05302524 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302525 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302526 sc->sc_flags |= SC_OP_TSF_RESET;
2527 }
Sujith5640b082008-10-29 10:16:06 +05302528
Sujith5640b082008-10-29 10:16:06 +05302529 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302530 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302531
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302532 /*
2533 * Enable MIB interrupts when there are hardware phy counters.
2534 * Note we only do this (at the moment) for station mode.
2535 */
Sujith4af9cf42009-02-12 10:06:47 +05302536 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002537 (conf->type == NL80211_IFTYPE_ADHOC) ||
2538 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05302539 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05302540 sc->imask |= ATH9K_INT_TSFOOR;
2541 }
2542
Sujith17d79042009-02-09 13:27:03 +05302543 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302544
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05302545 if (conf->type == NL80211_IFTYPE_AP ||
2546 conf->type == NL80211_IFTYPE_ADHOC ||
2547 conf->type == NL80211_IFTYPE_MONITOR)
Sujith415f7382009-04-13 21:56:46 +05302548 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002549
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002550out:
Sujith141b38b2009-02-04 08:10:07 +05302551 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002552 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002553}
2554
2555static void ath9k_remove_interface(struct ieee80211_hw *hw,
2556 struct ieee80211_if_init_conf *conf)
2557{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002558 struct ath_wiphy *aphy = hw->priv;
2559 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302560 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002561 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002562
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002563 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002564
Sujith141b38b2009-02-04 08:10:07 +05302565 mutex_lock(&sc->mutex);
2566
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002567 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302568 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002569
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002570 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002571 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2572 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2573 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302574 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002575 ath_beacon_return(sc, avp);
2576 }
2577
Sujith672840a2008-08-11 14:05:08 +05302578 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002579
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002580 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2581 if (sc->beacon.bslot[i] == conf->vif) {
2582 printk(KERN_DEBUG "%s: vif had allocated beacon "
2583 "slot\n", __func__);
2584 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002585 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002586 }
2587 }
2588
Sujith17d79042009-02-09 13:27:03 +05302589 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302590
2591 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592}
2593
Johannes Berge8975582008-10-09 12:18:51 +02002594static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002595{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002596 struct ath_wiphy *aphy = hw->priv;
2597 struct ath_softc *sc = aphy->sc;
Johannes Berge8975582008-10-09 12:18:51 +02002598 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302599 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002600 bool all_wiphys_idle = false, disable_radio = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002601
Sujithaa33de02008-12-18 11:40:16 +05302602 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302603
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002604 /* Leave this as the first check */
2605 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2606
2607 spin_lock_bh(&sc->wiphy_lock);
2608 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2609 spin_unlock_bh(&sc->wiphy_lock);
2610
2611 if (conf->flags & IEEE80211_CONF_IDLE){
2612 if (all_wiphys_idle)
2613 disable_radio = true;
2614 }
2615 else if (all_wiphys_idle) {
2616 ath_radio_enable(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002617 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002618 "not-idle: enabling radio\n");
2619 }
2620 }
2621
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302622 if (changed & IEEE80211_CONF_CHANGE_PS) {
2623 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302624 if (!(ah->caps.hw_caps &
2625 ATH9K_HW_CAP_AUTOSLEEP)) {
2626 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2627 sc->imask |= ATH9K_INT_TIM_TIMER;
2628 ath9k_hw_set_interrupts(sc->sc_ah,
2629 sc->imask);
2630 }
2631 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302632 }
Gabor Juhos96148322009-07-24 17:27:21 +02002633 sc->ps_enabled = true;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302634 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02002635 sc->ps_enabled = false;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002636 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302637 if (!(ah->caps.hw_caps &
2638 ATH9K_HW_CAP_AUTOSLEEP)) {
2639 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002640 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2641 SC_OP_WAIT_FOR_CAB |
2642 SC_OP_WAIT_FOR_PSPOLL_DATA |
2643 SC_OP_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302644 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2645 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2646 ath9k_hw_set_interrupts(sc->sc_ah,
2647 sc->imask);
2648 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302649 }
2650 }
2651 }
2652
Johannes Berg47979382009-01-07 10:13:27 +01002653 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302654 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002655 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002656
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002657 aphy->chan_idx = pos;
2658 aphy->chan_is_ht = conf_is_ht(conf);
2659
Jouni Malinen8089cc42009-03-03 19:23:38 +02002660 if (aphy->state == ATH_WIPHY_SCAN ||
2661 aphy->state == ATH_WIPHY_ACTIVE)
2662 ath9k_wiphy_pause_all_forced(sc, aphy);
2663 else {
2664 /*
2665 * Do not change operational channel based on a paused
2666 * wiphy changes.
2667 */
2668 goto skip_chan_change;
2669 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002670
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002671 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
Sujith04bd46382008-11-28 22:18:05 +05302672 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002673
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002674 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002675 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302676
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002677 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302678
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002679 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002680 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302681 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302682 return -EINVAL;
2683 }
Sujith094d05d2008-12-12 11:57:43 +05302684 }
Sujith86b89ee2008-08-07 10:54:57 +05302685
Jouni Malinen8089cc42009-03-03 19:23:38 +02002686skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002687 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302688 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002689
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002690 if (disable_radio) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002691 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002692 ath_radio_disable(sc);
2693 }
2694
Sujithaa33de02008-12-18 11:40:16 +05302695 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302696
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002697 return 0;
2698}
2699
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002700#define SUPPORTED_FILTERS \
2701 (FIF_PROMISC_IN_BSS | \
2702 FIF_ALLMULTI | \
2703 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04002704 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002705 FIF_OTHER_BSS | \
2706 FIF_BCN_PRBRESP_PROMISC | \
2707 FIF_FCSFAIL)
2708
Sujith7dcfdcd2008-08-11 14:03:13 +05302709/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002710static void ath9k_configure_filter(struct ieee80211_hw *hw,
2711 unsigned int changed_flags,
2712 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002713 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002714{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002715 struct ath_wiphy *aphy = hw->priv;
2716 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302717 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002718
2719 changed_flags &= SUPPORTED_FILTERS;
2720 *total_flags &= SUPPORTED_FILTERS;
2721
Sujithb77f4832008-12-07 21:44:03 +05302722 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002723 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302724 rfilt = ath_calcrxfilter(sc);
2725 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002726 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302727
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002728 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002729}
2730
2731static void ath9k_sta_notify(struct ieee80211_hw *hw,
2732 struct ieee80211_vif *vif,
2733 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002734 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002735{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002736 struct ath_wiphy *aphy = hw->priv;
2737 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002738
2739 switch (cmd) {
2740 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302741 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002742 break;
2743 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302744 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002745 break;
2746 default:
2747 break;
2748 }
2749}
2750
Sujith141b38b2009-02-04 08:10:07 +05302751static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002752 const struct ieee80211_tx_queue_params *params)
2753{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002754 struct ath_wiphy *aphy = hw->priv;
2755 struct ath_softc *sc = aphy->sc;
Sujithea9880f2008-08-07 10:53:10 +05302756 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002757 int ret = 0, qnum;
2758
2759 if (queue >= WME_NUM_AC)
2760 return 0;
2761
Sujith141b38b2009-02-04 08:10:07 +05302762 mutex_lock(&sc->mutex);
2763
Sujith1ffb0612009-03-30 15:28:46 +05302764 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2765
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002766 qi.tqi_aifs = params->aifs;
2767 qi.tqi_cwmin = params->cw_min;
2768 qi.tqi_cwmax = params->cw_max;
2769 qi.tqi_burstTime = params->txop;
2770 qnum = ath_get_hal_qnum(queue, sc);
2771
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002772 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Sujith04bd46382008-11-28 22:18:05 +05302773 "Configure tx [queue/halq] [%d/%d], "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002774 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
Sujith04bd46382008-11-28 22:18:05 +05302775 queue, qnum, params->aifs, params->cw_min,
2776 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002777
2778 ret = ath_txq_update(sc, qnum, &qi);
2779 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002780 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002781
Sujith141b38b2009-02-04 08:10:07 +05302782 mutex_unlock(&sc->mutex);
2783
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002784 return ret;
2785}
2786
2787static int ath9k_set_key(struct ieee80211_hw *hw,
2788 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002789 struct ieee80211_vif *vif,
2790 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002791 struct ieee80211_key_conf *key)
2792{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002793 struct ath_wiphy *aphy = hw->priv;
2794 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002795 int ret = 0;
2796
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002797 if (modparam_nohwcrypt)
2798 return -ENOSPC;
2799
Sujith141b38b2009-02-04 08:10:07 +05302800 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302801 ath9k_ps_wakeup(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002802 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002803
2804 switch (cmd) {
2805 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002806 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002807 if (ret >= 0) {
2808 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002809 /* push IV and Michael MIC generation to stack */
2810 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302811 if (key->alg == ALG_TKIP)
2812 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002813 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2814 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002815 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002816 }
2817 break;
2818 case DISABLE_KEY:
2819 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002820 break;
2821 default:
2822 ret = -EINVAL;
2823 }
2824
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302825 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302826 mutex_unlock(&sc->mutex);
2827
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002828 return ret;
2829}
2830
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002831static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2832 struct ieee80211_vif *vif,
2833 struct ieee80211_bss_conf *bss_conf,
2834 u32 changed)
2835{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002836 struct ath_wiphy *aphy = hw->priv;
2837 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002838 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002839 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002840 struct ath_vif *avp = (void *)vif->drv_priv;
2841 u32 rfilt = 0;
2842 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002843
Sujith141b38b2009-02-04 08:10:07 +05302844 mutex_lock(&sc->mutex);
2845
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002846 /*
2847 * TODO: Need to decide which hw opmode to use for
2848 * multi-interface cases
2849 * XXX: This belongs into add_interface!
2850 */
2851 if (vif->type == NL80211_IFTYPE_AP &&
2852 ah->opmode != NL80211_IFTYPE_AP) {
2853 ah->opmode = NL80211_IFTYPE_STATION;
2854 ath9k_hw_setopmode(ah);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002855 memcpy(common->curbssid, common->macaddr, ETH_ALEN);
2856 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002857 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002858 /* Request full reset to get hw opmode changed properly */
2859 sc->sc_flags |= SC_OP_FULL_RESET;
2860 }
2861
2862 if ((changed & BSS_CHANGED_BSSID) &&
2863 !is_zero_ether_addr(bss_conf->bssid)) {
2864 switch (vif->type) {
2865 case NL80211_IFTYPE_STATION:
2866 case NL80211_IFTYPE_ADHOC:
2867 case NL80211_IFTYPE_MESH_POINT:
2868 /* Set BSSID */
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002869 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002870 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002871 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002872 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002873
2874 /* Set aggregation protection mode parameters */
2875 sc->config.ath_aggr_prot = 0;
2876
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002877 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002878 "RX filter 0x%x bssid %pM aid 0x%x\n",
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002879 rfilt, common->curbssid, common->curaid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002880
2881 /* need to reconfigure the beacon */
2882 sc->sc_flags &= ~SC_OP_BEACONS ;
2883
2884 break;
2885 default:
2886 break;
2887 }
2888 }
2889
2890 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2891 (vif->type == NL80211_IFTYPE_AP) ||
2892 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2893 if ((changed & BSS_CHANGED_BEACON) ||
2894 (changed & BSS_CHANGED_BEACON_ENABLED &&
2895 bss_conf->enable_beacon)) {
2896 /*
2897 * Allocate and setup the beacon frame.
2898 *
2899 * Stop any previous beacon DMA. This may be
2900 * necessary, for example, when an ibss merge
2901 * causes reconfiguration; we may be called
2902 * with beacon transmission active.
2903 */
2904 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2905
2906 error = ath_beacon_alloc(aphy, vif);
2907 if (!error)
2908 ath_beacon_config(sc, vif);
2909 }
2910 }
2911
2912 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2913 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2914 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2915 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2916 ath9k_hw_keysetmac(sc->sc_ah,
2917 (u16)i,
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002918 common->curbssid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002919 }
2920
2921 /* Only legacy IBSS for now */
2922 if (vif->type == NL80211_IFTYPE_ADHOC)
2923 ath_update_chainmask(sc, 0);
2924
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002925 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002926 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002927 bss_conf->use_short_preamble);
2928 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302929 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002930 else
Sujith672840a2008-08-11 14:05:08 +05302931 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002932 }
2933
2934 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002935 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002936 bss_conf->use_cts_prot);
2937 if (bss_conf->use_cts_prot &&
2938 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302939 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002940 else
Sujith672840a2008-08-11 14:05:08 +05302941 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002942 }
2943
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002944 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002945 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002946 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302947 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002948 }
Sujith141b38b2009-02-04 08:10:07 +05302949
Johannes Berg57c4d7b2009-04-23 16:10:04 +02002950 /*
2951 * The HW TSF has to be reset when the beacon interval changes.
2952 * We set the flag here, and ath_beacon_config_ap() would take this
2953 * into account when it gets called through the subsequent
2954 * config_interface() call - with IFCC_BEACON in the changed field.
2955 */
2956
2957 if (changed & BSS_CHANGED_BEACON_INT) {
2958 sc->sc_flags |= SC_OP_TSF_RESET;
2959 sc->beacon_interval = bss_conf->beacon_int;
2960 }
2961
Sujith141b38b2009-02-04 08:10:07 +05302962 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002963}
2964
2965static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2966{
2967 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002968 struct ath_wiphy *aphy = hw->priv;
2969 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002970
Sujith141b38b2009-02-04 08:10:07 +05302971 mutex_lock(&sc->mutex);
2972 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2973 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002974
2975 return tsf;
2976}
2977
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002978static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2979{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002980 struct ath_wiphy *aphy = hw->priv;
2981 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002982
Sujith141b38b2009-02-04 08:10:07 +05302983 mutex_lock(&sc->mutex);
2984 ath9k_hw_settsf64(sc->sc_ah, tsf);
2985 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002986}
2987
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002988static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2989{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002990 struct ath_wiphy *aphy = hw->priv;
2991 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002992
Sujith141b38b2009-02-04 08:10:07 +05302993 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002994
2995 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05302996 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002997 ath9k_ps_restore(sc);
2998
Sujith141b38b2009-02-04 08:10:07 +05302999 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003000}
3001
3002static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05303003 enum ieee80211_ampdu_mlme_action action,
3004 struct ieee80211_sta *sta,
3005 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003006{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003007 struct ath_wiphy *aphy = hw->priv;
3008 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003009 int ret = 0;
3010
3011 switch (action) {
3012 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05303013 if (!(sc->sc_flags & SC_OP_RXAGGR))
3014 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003015 break;
3016 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003017 break;
3018 case IEEE80211_AMPDU_TX_START:
Sujithf83da962009-07-23 15:32:37 +05303019 ath_tx_aggr_start(sc, sta, tid, ssn);
3020 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021 break;
3022 case IEEE80211_AMPDU_TX_STOP:
Sujithf83da962009-07-23 15:32:37 +05303023 ath_tx_aggr_stop(sc, sta, tid);
Johannes Berg17741cd2008-09-11 00:02:02 +02003024 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003025 break;
Johannes Bergb1720232009-03-23 17:28:39 +01003026 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05303027 ath_tx_aggr_resume(sc, sta, tid);
3028 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003029 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07003030 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003031 }
3032
3033 return ret;
3034}
3035
Sujith0c98de62009-03-03 10:16:45 +05303036static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
3037{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003038 struct ath_wiphy *aphy = hw->priv;
3039 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303040
Sujith3d832612009-08-21 12:00:28 +05303041 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003042 if (ath9k_wiphy_scanning(sc)) {
3043 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
3044 "same time\n");
3045 /*
3046 * Do not allow the concurrent scanning state for now. This
3047 * could be improved with scanning control moved into ath9k.
3048 */
Sujith3d832612009-08-21 12:00:28 +05303049 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003050 return;
3051 }
3052
3053 aphy->state = ATH_WIPHY_SCAN;
3054 ath9k_wiphy_pause_all_forced(sc, aphy);
3055
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303056 spin_lock_bh(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +05303057 sc->sc_flags |= SC_OP_SCANNING;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303058 spin_unlock_bh(&sc->ani_lock);
Sujith3d832612009-08-21 12:00:28 +05303059 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303060}
3061
3062static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
3063{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003064 struct ath_wiphy *aphy = hw->priv;
3065 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303066
Sujith3d832612009-08-21 12:00:28 +05303067 mutex_lock(&sc->mutex);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303068 spin_lock_bh(&sc->ani_lock);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003069 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05303070 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05303071 sc->sc_flags |= SC_OP_FULL_RESET;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303072 spin_unlock_bh(&sc->ani_lock);
Vivek Natarajand0bec342009-09-02 15:50:55 +05303073 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05303074 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303075}
3076
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003077struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003078 .tx = ath9k_tx,
3079 .start = ath9k_start,
3080 .stop = ath9k_stop,
3081 .add_interface = ath9k_add_interface,
3082 .remove_interface = ath9k_remove_interface,
3083 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003084 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003085 .sta_notify = ath9k_sta_notify,
3086 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003087 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003088 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003089 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003090 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003091 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02003092 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05303093 .sw_scan_start = ath9k_sw_scan_start,
3094 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05303095 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003096};
3097
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003098static struct {
3099 u32 version;
3100 const char * name;
3101} ath_mac_bb_names[] = {
3102 { AR_SREV_VERSION_5416_PCI, "5416" },
3103 { AR_SREV_VERSION_5416_PCIE, "5418" },
3104 { AR_SREV_VERSION_9100, "9100" },
3105 { AR_SREV_VERSION_9160, "9160" },
3106 { AR_SREV_VERSION_9280, "9280" },
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303107 { AR_SREV_VERSION_9285, "9285" },
3108 { AR_SREV_VERSION_9287, "9287" }
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003109};
3110
3111static struct {
3112 u16 version;
3113 const char * name;
3114} ath_rf_names[] = {
3115 { 0, "5133" },
3116 { AR_RAD5133_SREV_MAJOR, "5133" },
3117 { AR_RAD5122_SREV_MAJOR, "5122" },
3118 { AR_RAD2133_SREV_MAJOR, "2133" },
3119 { AR_RAD2122_SREV_MAJOR, "2122" }
3120};
3121
3122/*
3123 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3124 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003125const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003126ath_mac_bb_name(u32 mac_bb_version)
3127{
3128 int i;
3129
3130 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3131 if (ath_mac_bb_names[i].version == mac_bb_version) {
3132 return ath_mac_bb_names[i].name;
3133 }
3134 }
3135
3136 return "????";
3137}
3138
3139/*
3140 * Return the RF name. "????" is returned if the RF is unknown.
3141 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003142const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003143ath_rf_name(u16 rf_version)
3144{
3145 int i;
3146
3147 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3148 if (ath_rf_names[i].version == rf_version) {
3149 return ath_rf_names[i].name;
3150 }
3151 }
3152
3153 return "????";
3154}
3155
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003156static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003157{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303158 int error;
3159
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303160 /* Register rate control algorithm */
3161 error = ath_rate_control_register();
3162 if (error != 0) {
3163 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003164 "ath9k: Unable to register rate control "
3165 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303166 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003167 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303168 }
3169
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003170 error = ath9k_debug_create_root();
3171 if (error) {
3172 printk(KERN_ERR
3173 "ath9k: Unable to create debugfs root: %d\n",
3174 error);
3175 goto err_rate_unregister;
3176 }
3177
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003178 error = ath_pci_init();
3179 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003180 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003181 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003182 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003183 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003184 }
3185
Gabor Juhos09329d32009-01-14 20:17:07 +01003186 error = ath_ahb_init();
3187 if (error < 0) {
3188 error = -ENODEV;
3189 goto err_pci_exit;
3190 }
3191
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003192 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003193
Gabor Juhos09329d32009-01-14 20:17:07 +01003194 err_pci_exit:
3195 ath_pci_exit();
3196
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003197 err_remove_root:
3198 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003199 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303200 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003201 err_out:
3202 return error;
3203}
3204module_init(ath9k_init);
3205
3206static void __exit ath9k_exit(void)
3207{
Gabor Juhos09329d32009-01-14 20:17:07 +01003208 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003209 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003210 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003211 ath_rate_control_unregister();
Sujith04bd46382008-11-28 22:18:05 +05303212 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003213}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003214module_exit(ath9k_exit);