blob: 86374ad9313c764969063d2fe4ca179bc6237a1c [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. Rodriguezc46917b2009-09-13 02:42:02 -0700228 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
229 "Rate: %2dMbps, ratecode: %2d\n",
230 rate[i].bitrate / 10, rate[i].hw_value);
Sujithff37e332008-11-24 12:07:55 +0530231 }
232}
233
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530234static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
235 struct ieee80211_hw *hw)
236{
237 struct ieee80211_channel *curchan = hw->conf.channel;
238 struct ath9k_channel *channel;
239 u8 chan_idx;
240
241 chan_idx = curchan->hw_value;
242 channel = &sc->sc_ah->channels[chan_idx];
243 ath9k_update_ichannel(sc, hw, channel);
244 return channel;
245}
246
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700247static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700248{
249 unsigned long flags;
250 bool ret;
251
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700252 spin_lock_irqsave(&sc->sc_pm_lock, flags);
253 ret = ath9k_hw_setpower(sc->sc_ah, mode);
254 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700255
256 return ret;
257}
258
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700259void ath9k_ps_wakeup(struct ath_softc *sc)
260{
261 unsigned long flags;
262
263 spin_lock_irqsave(&sc->sc_pm_lock, flags);
264 if (++sc->ps_usecount != 1)
265 goto unlock;
266
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700267 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700268
269 unlock:
270 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
271}
272
273void ath9k_ps_restore(struct ath_softc *sc)
274{
275 unsigned long flags;
276
277 spin_lock_irqsave(&sc->sc_pm_lock, flags);
278 if (--sc->ps_usecount != 0)
279 goto unlock;
280
281 if (sc->ps_enabled &&
282 !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
283 SC_OP_WAIT_FOR_CAB |
284 SC_OP_WAIT_FOR_PSPOLL_DATA |
285 SC_OP_WAIT_FOR_TX_ACK)))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700286 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Luis R. Rodrigueza91d75ae2009-09-09 20:29:18 -0700287
288 unlock:
289 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
290}
291
Sujithff37e332008-11-24 12:07:55 +0530292/*
293 * Set/change channels. If the channel is really being changed, it's done
294 * by reseting the chip. To accomplish this we must first cleanup any pending
295 * DMA, then restart stuff.
296*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200297int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
298 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530299{
Sujithcbe61d82009-02-09 13:27:12 +0530300 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700301 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700302 struct ieee80211_conf *conf = &common->hw->conf;
Sujithff37e332008-11-24 12:07:55 +0530303 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800304 struct ieee80211_channel *channel = hw->conf.channel;
305 int r;
Sujithff37e332008-11-24 12:07:55 +0530306
307 if (sc->sc_flags & SC_OP_INVALID)
308 return -EIO;
309
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530310 ath9k_ps_wakeup(sc);
311
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800312 /*
313 * This is only performed if the channel settings have
314 * actually changed.
315 *
316 * To switch channels clear any pending DMA operations;
317 * wait long enough for the RX fifo to drain, reset the
318 * hardware at the new frequency, and then re-enable
319 * the relevant bits of the h/w.
320 */
321 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530322 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800323 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530324
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800325 /* XXX: do not flush receive queue here. We don't want
326 * to flush data frames already in queue because of
327 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530328
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800329 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
330 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530331
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700332 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700333 "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700334 sc->sc_ah->curchan->channel,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700335 channel->center_freq, conf_is_ht40(conf));
Sujith99405f92008-11-24 12:08:35 +0530336
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800337 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800338
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800339 r = ath9k_hw_reset(ah, hchan, fastcc);
340 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700341 ath_print(common, ATH_DBG_FATAL,
342 "Unable to reset channel (%u Mhz) "
343 "reset status %d\n",
344 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530345 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200346 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530347 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800348 spin_unlock_bh(&sc->sc_resetlock);
349
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800350 sc->sc_flags &= ~SC_OP_FULL_RESET;
351
352 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700353 ath_print(common, ATH_DBG_FATAL,
354 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200355 r = -EIO;
356 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800357 }
358
359 ath_cache_conf_rate(sc, &hw->conf);
360 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530361 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200362
363 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530364 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200365 return r;
Sujithff37e332008-11-24 12:07:55 +0530366}
367
368/*
369 * This routine performs the periodic noise floor calibration function
370 * that is used to adjust and optimize the chip performance. This
371 * takes environmental changes (location, temperature) into account.
372 * When the task is complete, it reschedules itself depending on the
373 * appropriate interval that was calculated.
374 */
375static void ath_ani_calibrate(unsigned long data)
376{
Sujith20977d32009-02-20 15:13:28 +0530377 struct ath_softc *sc = (struct ath_softc *)data;
378 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700379 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530380 bool longcal = false;
381 bool shortcal = false;
382 bool aniflag = false;
383 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530384 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530385
Sujith20977d32009-02-20 15:13:28 +0530386 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
387 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530388
389 /*
390 * don't calibrate when we're scanning.
391 * we are most likely not on our home channel.
392 */
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530393 spin_lock(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +0530394 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530395 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530396
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300397 /* Only calibrate if awake */
398 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
399 goto set_timer;
400
401 ath9k_ps_wakeup(sc);
402
Sujithff37e332008-11-24 12:07:55 +0530403 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530404 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530405 longcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700406 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530407 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530408 }
409
Sujith17d79042009-02-09 13:27:03 +0530410 /* Short calibration applies only while caldone is false */
411 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530412 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530413 shortcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700414 ath_print(common, ATH_DBG_ANI,
415 "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530416 sc->ani.shortcal_timer = timestamp;
417 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530418 }
419 } else {
Sujith17d79042009-02-09 13:27:03 +0530420 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530421 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530422 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
423 if (sc->ani.caldone)
424 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530425 }
426 }
427
428 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530429 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530430 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530431 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530432 }
433
434 /* Skip all processing if there's nothing to do. */
435 if (longcal || shortcal || aniflag) {
436 /* Call ANI routine if necessary */
437 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530438 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530439
440 /* Perform calibration if necessary */
441 if (longcal || shortcal) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700442 sc->ani.caldone =
443 ath9k_hw_calibrate(ah,
444 ah->curchan,
445 common->rx_chainmask,
446 longcal);
Sujithff37e332008-11-24 12:07:55 +0530447
Sujith379f0442009-04-13 21:56:48 +0530448 if (longcal)
449 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
450 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530451
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700452 ath_print(common, ATH_DBG_ANI,
453 " calibrate chan %u/%x nf: %d\n",
454 ah->curchan->channel,
455 ah->curchan->channelFlags,
456 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530457 }
458 }
459
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300460 ath9k_ps_restore(sc);
461
Sujith20977d32009-02-20 15:13:28 +0530462set_timer:
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530463 spin_unlock(&sc->ani_lock);
Sujithff37e332008-11-24 12:07:55 +0530464 /*
465 * Set timer interval based on previous results.
466 * The interval must be the shortest necessary to satisfy ANI,
467 * short calibration and long calibration.
468 */
Sujithaac92072008-12-02 18:37:54 +0530469 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530470 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530471 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530472 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530473 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530474
Sujith17d79042009-02-09 13:27:03 +0530475 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530476}
477
Sujith415f7382009-04-13 21:56:46 +0530478static void ath_start_ani(struct ath_softc *sc)
479{
480 unsigned long timestamp = jiffies_to_msecs(jiffies);
481
482 sc->ani.longcal_timer = timestamp;
483 sc->ani.shortcal_timer = timestamp;
484 sc->ani.checkani_timer = timestamp;
485
486 mod_timer(&sc->ani.timer,
487 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
488}
489
Sujithff37e332008-11-24 12:07:55 +0530490/*
491 * Update tx/rx chainmask. For legacy association,
492 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530493 * the chainmask configuration, for bt coexistence, use
494 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530495 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200496void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530497{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700498 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700499 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700500
Sujith3d832612009-08-21 12:00:28 +0530501 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700502 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700503 common->tx_chainmask = ah->caps.tx_chainmask;
504 common->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530505 } else {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700506 common->tx_chainmask = 1;
507 common->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530508 }
509
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700510 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700511 "tx chmask: %d, rx chmask: %d\n",
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700512 common->tx_chainmask,
513 common->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530514}
515
516static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
517{
518 struct ath_node *an;
519
520 an = (struct ath_node *)sta->drv_priv;
521
Sujith87792ef2009-03-30 15:28:48 +0530522 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530523 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530524 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530525 sta->ht_cap.ampdu_factor);
526 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400527 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530528 }
Sujithff37e332008-11-24 12:07:55 +0530529}
530
531static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
532{
533 struct ath_node *an = (struct ath_node *)sta->drv_priv;
534
535 if (sc->sc_flags & SC_OP_TXAGGR)
536 ath_tx_node_cleanup(sc, an);
537}
538
539static void ath9k_tasklet(unsigned long data)
540{
541 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700542 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700543 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700544
Sujith17d79042009-02-09 13:27:03 +0530545 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530546
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400547 ath9k_ps_wakeup(sc);
548
Sujithff37e332008-11-24 12:07:55 +0530549 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530550 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400551 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530552 return;
Sujithff37e332008-11-24 12:07:55 +0530553 }
554
Sujith063d8be2009-03-30 15:28:49 +0530555 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
556 spin_lock_bh(&sc->rx.rxflushlock);
557 ath_rx_tasklet(sc, 0);
558 spin_unlock_bh(&sc->rx.rxflushlock);
559 }
560
561 if (status & ATH9K_INT_TX)
562 ath_tx_tasklet(sc);
563
Gabor Juhos96148322009-07-24 17:27:21 +0200564 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300565 /*
566 * TSF sync does not look correct; remain awake to sync with
567 * the next Beacon.
568 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700569 ath_print(common, ATH_DBG_PS,
570 "TSFOOR - Sync with next Beacon\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300571 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300572 }
573
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700574 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530575 if (status & ATH9K_INT_GENTIMER)
576 ath_gen_timer_isr(sc->sc_ah);
577
Sujithff37e332008-11-24 12:07:55 +0530578 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700579 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400580 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530581}
582
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100583irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530584{
Sujith063d8be2009-03-30 15:28:49 +0530585#define SCHED_INTR ( \
586 ATH9K_INT_FATAL | \
587 ATH9K_INT_RXORN | \
588 ATH9K_INT_RXEOL | \
589 ATH9K_INT_RX | \
590 ATH9K_INT_TX | \
591 ATH9K_INT_BMISS | \
592 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530593 ATH9K_INT_TSFOOR | \
594 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530595
Sujithff37e332008-11-24 12:07:55 +0530596 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530597 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530598 enum ath9k_int status;
599 bool sched = false;
600
Sujith063d8be2009-03-30 15:28:49 +0530601 /*
602 * The hardware is not ready/present, don't
603 * touch anything. Note this can happen early
604 * on if the IRQ is shared.
605 */
606 if (sc->sc_flags & SC_OP_INVALID)
607 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530608
Sujithff37e332008-11-24 12:07:55 +0530609
Sujith063d8be2009-03-30 15:28:49 +0530610 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530611
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400612 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530613 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530614
Sujith063d8be2009-03-30 15:28:49 +0530615 /*
616 * Figure out the reason(s) for the interrupt. Note
617 * that the hal returns a pseudo-ISR that may include
618 * bits we haven't explicitly enabled so we mask the
619 * value to insure we only process bits we requested.
620 */
621 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
622 status &= sc->imask; /* discard unasked-for bits */
623
624 /*
625 * If there are no status bits set, then this interrupt was not
626 * for me (should have been caught above).
627 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400628 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530629 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530630
631 /* Cache the status */
632 sc->intrstatus = status;
633
634 if (status & SCHED_INTR)
635 sched = true;
636
637 /*
638 * If a FATAL or RXORN interrupt is received, we have to reset the
639 * chip immediately.
640 */
641 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
642 goto chip_reset;
643
644 if (status & ATH9K_INT_SWBA)
645 tasklet_schedule(&sc->bcon_tasklet);
646
647 if (status & ATH9K_INT_TXURN)
648 ath9k_hw_updatetxtriglevel(ah, true);
649
650 if (status & ATH9K_INT_MIB) {
651 /*
652 * Disable interrupts until we service the MIB
653 * interrupt; otherwise it will continue to
654 * fire.
655 */
656 ath9k_hw_set_interrupts(ah, 0);
657 /*
658 * Let the hal handle the event. We assume
659 * it will clear whatever condition caused
660 * the interrupt.
661 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530662 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530663 ath9k_hw_set_interrupts(ah, sc->imask);
664 }
665
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400666 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
667 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530668 /* Clear RxAbort bit so that we can
669 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700670 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400671 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith063d8be2009-03-30 15:28:49 +0530672 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
673 }
Sujith063d8be2009-03-30 15:28:49 +0530674
675chip_reset:
676
Sujith817e11d2008-12-07 21:42:44 +0530677 ath_debug_stat_interrupt(sc, status);
678
Sujithff37e332008-11-24 12:07:55 +0530679 if (sched) {
680 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530681 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530682 tasklet_schedule(&sc->intr_tq);
683 }
684
685 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530686
687#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530688}
689
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700690static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530691 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530692 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700693{
694 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695
696 switch (chan->band) {
697 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530698 switch(channel_type) {
699 case NL80211_CHAN_NO_HT:
700 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700701 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530702 break;
703 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700704 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530705 break;
706 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530708 break;
709 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700710 break;
711 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530712 switch(channel_type) {
713 case NL80211_CHAN_NO_HT:
714 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530716 break;
717 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530719 break;
720 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700721 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530722 break;
723 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700724 break;
725 default:
726 break;
727 }
728
729 return chanmode;
730}
731
Jouni Malinen6ace2892008-12-17 13:32:17 +0200732static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200733 struct ath9k_keyval *hk, const u8 *addr,
734 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200736 const u8 *key_rxmic;
737 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700738
Jouni Malinen6ace2892008-12-17 13:32:17 +0200739 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
740 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700741
742 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200743 /*
744 * Group key installation - only two key cache entries are used
745 * regardless of splitmic capability since group key is only
746 * used either for TX or RX.
747 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200748 if (authenticator) {
749 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
750 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
751 } else {
752 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
753 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
754 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200755 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700756 }
Sujith17d79042009-02-09 13:27:03 +0530757 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200758 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700759 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
760 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200761 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200763
764 /* Separate key cache entries for TX and RX */
765
766 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700767 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200768 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
769 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700770 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
771 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700772 return 0;
773 }
774
775 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
776 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200777 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200778}
779
780static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
781{
782 int i;
783
Sujith17d79042009-02-09 13:27:03 +0530784 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
785 if (test_bit(i, sc->keymap) ||
786 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200787 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530788 if (sc->splitmic &&
789 (test_bit(i + 32, sc->keymap) ||
790 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200791 continue; /* At least one part of TKIP key allocated */
792
793 /* Found a free slot for a TKIP key */
794 return i;
795 }
796 return -1;
797}
798
799static int ath_reserve_key_cache_slot(struct ath_softc *sc)
800{
801 int i;
802
803 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530804 if (sc->splitmic) {
805 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
806 if (!test_bit(i, sc->keymap) &&
807 (test_bit(i + 32, sc->keymap) ||
808 test_bit(i + 64, sc->keymap) ||
809 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200810 return i;
Sujith17d79042009-02-09 13:27:03 +0530811 if (!test_bit(i + 32, sc->keymap) &&
812 (test_bit(i, sc->keymap) ||
813 test_bit(i + 64, sc->keymap) ||
814 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200815 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530816 if (!test_bit(i + 64, sc->keymap) &&
817 (test_bit(i , sc->keymap) ||
818 test_bit(i + 32, sc->keymap) ||
819 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200820 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530821 if (!test_bit(i + 64 + 32, sc->keymap) &&
822 (test_bit(i, sc->keymap) ||
823 test_bit(i + 32, sc->keymap) ||
824 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200825 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200826 }
827 } else {
Sujith17d79042009-02-09 13:27:03 +0530828 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
829 if (!test_bit(i, sc->keymap) &&
830 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200831 return i;
Sujith17d79042009-02-09 13:27:03 +0530832 if (test_bit(i, sc->keymap) &&
833 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200834 return i + 64;
835 }
836 }
837
838 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530839 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200840 /* Do not allow slots that could be needed for TKIP group keys
841 * to be used. This limitation could be removed if we know that
842 * TKIP will not be used. */
843 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
844 continue;
Sujith17d79042009-02-09 13:27:03 +0530845 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200846 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
847 continue;
848 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
849 continue;
850 }
851
Sujith17d79042009-02-09 13:27:03 +0530852 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200853 return i; /* Found a free slot for a key */
854 }
855
856 /* No free slot found */
857 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700858}
859
860static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200861 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100862 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700863 struct ieee80211_key_conf *key)
864{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700865 struct ath9k_keyval hk;
866 const u8 *mac = NULL;
867 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200868 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869
870 memset(&hk, 0, sizeof(hk));
871
872 switch (key->alg) {
873 case ALG_WEP:
874 hk.kv_type = ATH9K_CIPHER_WEP;
875 break;
876 case ALG_TKIP:
877 hk.kv_type = ATH9K_CIPHER_TKIP;
878 break;
879 case ALG_CCMP:
880 hk.kv_type = ATH9K_CIPHER_AES_CCM;
881 break;
882 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200883 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700884 }
885
Jouni Malinen6ace2892008-12-17 13:32:17 +0200886 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700887 memcpy(hk.kv_val, key->key, key->keylen);
888
Jouni Malinen6ace2892008-12-17 13:32:17 +0200889 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
890 /* For now, use the default keys for broadcast keys. This may
891 * need to change with virtual interfaces. */
892 idx = key->keyidx;
893 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100894 if (WARN_ON(!sta))
895 return -EOPNOTSUPP;
896 mac = sta->addr;
897
Jouni Malinen6ace2892008-12-17 13:32:17 +0200898 if (vif->type != NL80211_IFTYPE_AP) {
899 /* Only keyidx 0 should be used with unicast key, but
900 * allow this for client mode for now. */
901 idx = key->keyidx;
902 } else
903 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700904 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100905 if (WARN_ON(!sta))
906 return -EOPNOTSUPP;
907 mac = sta->addr;
908
Jouni Malinen6ace2892008-12-17 13:32:17 +0200909 if (key->alg == ALG_TKIP)
910 idx = ath_reserve_key_cache_slot_tkip(sc);
911 else
912 idx = ath_reserve_key_cache_slot(sc);
913 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200914 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700915 }
916
917 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200918 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
919 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700920 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200921 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700922
923 if (!ret)
924 return -EIO;
925
Sujith17d79042009-02-09 13:27:03 +0530926 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200927 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530928 set_bit(idx + 64, sc->keymap);
929 if (sc->splitmic) {
930 set_bit(idx + 32, sc->keymap);
931 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200932 }
933 }
934
935 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700936}
937
938static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
939{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200940 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
941 if (key->hw_key_idx < IEEE80211_WEP_NKID)
942 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700943
Sujith17d79042009-02-09 13:27:03 +0530944 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200945 if (key->alg != ALG_TKIP)
946 return;
947
Sujith17d79042009-02-09 13:27:03 +0530948 clear_bit(key->hw_key_idx + 64, sc->keymap);
949 if (sc->splitmic) {
950 clear_bit(key->hw_key_idx + 32, sc->keymap);
951 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200952 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700953}
954
Sujitheb2599c2009-01-23 11:20:44 +0530955static void setup_ht_cap(struct ath_softc *sc,
956 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700957{
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700958 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530959 u8 tx_streams, rx_streams;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700960
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200961 ht_info->ht_supported = true;
962 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
963 IEEE80211_HT_CAP_SM_PS |
964 IEEE80211_HT_CAP_SGI_40 |
965 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700966
Sujith9e98ac62009-07-23 15:32:34 +0530967 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
968 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530969
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200970 /* set up supported mcs set */
971 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700972 tx_streams = !(common->tx_chainmask & (common->tx_chainmask - 1)) ?
973 1 : 2;
974 rx_streams = !(common->rx_chainmask & (common->rx_chainmask - 1)) ?
975 1 : 2;
Sujitheb2599c2009-01-23 11:20:44 +0530976
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530977 if (tx_streams != rx_streams) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700978 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700979 "TX streams %d, RX streams: %d\n",
980 tx_streams, rx_streams);
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530981 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
982 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
983 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
Sujitheb2599c2009-01-23 11:20:44 +0530984 }
985
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530986 ht_info->mcs.rx_mask[0] = 0xff;
987 if (rx_streams >= 2)
988 ht_info->mcs.rx_mask[1] = 0xff;
989
990 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700991}
992
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530993static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530994 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530995 struct ieee80211_bss_conf *bss_conf)
996{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700997 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700998 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530999
1000 if (bss_conf->assoc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001001 ath_print(common, ATH_DBG_CONFIG,
1002 "Bss Info ASSOC %d, bssid: %pM\n",
1003 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301004
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301005 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001006 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001007 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +03001008
Senthil Balasubramanian2664f202009-06-24 18:56:39 +05301009 /*
1010 * Request a re-configuration of Beacon related timers
1011 * on the receipt of the first Beacon frame (i.e.,
1012 * after time sync with the AP).
1013 */
1014 sc->sc_flags |= SC_OP_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301015
1016 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001017 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301018
1019 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +05301020 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301021
Sujith415f7382009-04-13 21:56:46 +05301022 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301023 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001024 ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001025 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05301026 /* Stop ANI */
1027 del_timer_sync(&sc->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301028 }
1029}
1030
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301031/********************************/
1032/* LED functions */
1033/********************************/
1034
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301035static void ath_led_blink_work(struct work_struct *work)
1036{
1037 struct ath_softc *sc = container_of(work, struct ath_softc,
1038 ath_led_blink_work.work);
1039
1040 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
1041 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301042
1043 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
1044 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301045 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301046 else
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301047 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301048 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301049
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001050 ieee80211_queue_delayed_work(sc->hw,
1051 &sc->ath_led_blink_work,
1052 (sc->sc_flags & SC_OP_LED_ON) ?
1053 msecs_to_jiffies(sc->led_off_duration) :
1054 msecs_to_jiffies(sc->led_on_duration));
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301055
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301056 sc->led_on_duration = sc->led_on_cnt ?
1057 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
1058 ATH_LED_ON_DURATION_IDLE;
1059 sc->led_off_duration = sc->led_off_cnt ?
1060 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
1061 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301062 sc->led_on_cnt = sc->led_off_cnt = 0;
1063 if (sc->sc_flags & SC_OP_LED_ON)
1064 sc->sc_flags &= ~SC_OP_LED_ON;
1065 else
1066 sc->sc_flags |= SC_OP_LED_ON;
1067}
1068
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301069static void ath_led_brightness(struct led_classdev *led_cdev,
1070 enum led_brightness brightness)
1071{
1072 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1073 struct ath_softc *sc = led->sc;
1074
1075 switch (brightness) {
1076 case LED_OFF:
1077 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301078 led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301079 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301080 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301081 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301082 if (led->led_type == ATH_LED_RADIO)
1083 sc->sc_flags &= ~SC_OP_LED_ON;
1084 } else {
1085 sc->led_off_cnt++;
1086 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301087 break;
1088 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301089 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301090 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001091 ieee80211_queue_delayed_work(sc->hw,
1092 &sc->ath_led_blink_work, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301093 } else if (led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301094 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301095 sc->sc_flags |= SC_OP_LED_ON;
1096 } else {
1097 sc->led_on_cnt++;
1098 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301099 break;
1100 default:
1101 break;
1102 }
1103}
1104
1105static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1106 char *trigger)
1107{
1108 int ret;
1109
1110 led->sc = sc;
1111 led->led_cdev.name = led->name;
1112 led->led_cdev.default_trigger = trigger;
1113 led->led_cdev.brightness_set = ath_led_brightness;
1114
1115 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1116 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001117 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1118 "Failed to register led:%s", led->name);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301119 else
1120 led->registered = 1;
1121 return ret;
1122}
1123
1124static void ath_unregister_led(struct ath_led *led)
1125{
1126 if (led->registered) {
1127 led_classdev_unregister(&led->led_cdev);
1128 led->registered = 0;
1129 }
1130}
1131
1132static void ath_deinit_leds(struct ath_softc *sc)
1133{
1134 ath_unregister_led(&sc->assoc_led);
1135 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1136 ath_unregister_led(&sc->tx_led);
1137 ath_unregister_led(&sc->rx_led);
1138 ath_unregister_led(&sc->radio_led);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301139 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301140}
1141
1142static void ath_init_leds(struct ath_softc *sc)
1143{
1144 char *trigger;
1145 int ret;
1146
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301147 if (AR_SREV_9287(sc->sc_ah))
1148 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1149 else
1150 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1151
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301152 /* Configure gpio 1 for output */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301153 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301154 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1155 /* LED off, active low */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301156 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301157
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301158 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1159
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301160 trigger = ieee80211_get_radio_led_name(sc->hw);
1161 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001162 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301163 ret = ath_register_led(sc, &sc->radio_led, trigger);
1164 sc->radio_led.led_type = ATH_LED_RADIO;
1165 if (ret)
1166 goto fail;
1167
1168 trigger = ieee80211_get_assoc_led_name(sc->hw);
1169 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001170 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301171 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1172 sc->assoc_led.led_type = ATH_LED_ASSOC;
1173 if (ret)
1174 goto fail;
1175
1176 trigger = ieee80211_get_tx_led_name(sc->hw);
1177 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001178 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301179 ret = ath_register_led(sc, &sc->tx_led, trigger);
1180 sc->tx_led.led_type = ATH_LED_TX;
1181 if (ret)
1182 goto fail;
1183
1184 trigger = ieee80211_get_rx_led_name(sc->hw);
1185 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001186 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301187 ret = ath_register_led(sc, &sc->rx_led, trigger);
1188 sc->rx_led.led_type = ATH_LED_RX;
1189 if (ret)
1190 goto fail;
1191
1192 return;
1193
1194fail:
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001195 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301196 ath_deinit_leds(sc);
1197}
1198
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001199void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301200{
Sujithcbe61d82009-02-09 13:27:12 +05301201 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001202 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001203 struct ieee80211_channel *channel = sc->hw->conf.channel;
1204 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301205
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301206 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301207 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +05301208
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301209 if (!ah->curchan)
1210 ah->curchan = ath_get_curchannel(sc, sc->hw);
1211
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301212 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301213 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001214 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001215 ath_print(common, ATH_DBG_FATAL,
1216 "Unable to reset channel %u (%uMhz) ",
1217 "reset status %d\n",
1218 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301219 }
1220 spin_unlock_bh(&sc->sc_resetlock);
1221
1222 ath_update_txpow(sc);
1223 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001224 ath_print(common, ATH_DBG_FATAL,
1225 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301226 return;
1227 }
1228
1229 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001230 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301231
1232 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301233 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301234
1235 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301236 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301237 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301238 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301239
1240 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301241 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301242}
1243
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001244void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301245{
Sujithcbe61d82009-02-09 13:27:12 +05301246 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001247 struct ieee80211_channel *channel = sc->hw->conf.channel;
1248 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301249
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301250 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301251 ieee80211_stop_queues(sc->hw);
1252
1253 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301254 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1255 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301256
1257 /* Disable interrupts */
1258 ath9k_hw_set_interrupts(ah, 0);
1259
Sujith043a0402009-01-16 21:38:47 +05301260 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301261 ath_stoprecv(sc); /* turn off frame recv */
1262 ath_flushrecv(sc); /* flush recv queue */
1263
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301264 if (!ah->curchan)
1265 ah->curchan = ath_get_curchannel(sc, sc->hw);
1266
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301267 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301268 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001269 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001270 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1271 "Unable to reset channel %u (%uMhz) "
1272 "reset status %d\n",
1273 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301274 }
1275 spin_unlock_bh(&sc->sc_resetlock);
1276
1277 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301278 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301279 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001280 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301281}
1282
Gabor Juhos5077fd32009-03-06 11:17:55 +01001283/*******************/
1284/* Rfkill */
1285/*******************/
1286
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301287static bool ath_is_rfkill_set(struct ath_softc *sc)
1288{
Sujithcbe61d82009-02-09 13:27:12 +05301289 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301290
Sujith2660b812009-02-09 13:27:26 +05301291 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1292 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301293}
1294
Johannes Berg3b319aa2009-06-13 14:50:26 +05301295static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301296{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301297 struct ath_wiphy *aphy = hw->priv;
1298 struct ath_softc *sc = aphy->sc;
1299 bool blocked = !!ath_is_rfkill_set(sc);
1300
1301 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
Johannes Berg19d337d2009-06-02 13:01:37 +02001302}
1303
Johannes Berg3b319aa2009-06-13 14:50:26 +05301304static void ath_start_rfkill_poll(struct ath_softc *sc)
Johannes Berg19d337d2009-06-02 13:01:37 +02001305{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301306 struct ath_hw *ah = sc->sc_ah;
Johannes Berg19d337d2009-06-02 13:01:37 +02001307
Johannes Berg3b319aa2009-06-13 14:50:26 +05301308 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1309 wiphy_rfkill_start_polling(sc->hw->wiphy);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301310}
1311
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001312void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001313{
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001314 struct ath_hw *ah = sc->sc_ah;
1315 struct ath_common *common = ath9k_hw_common(ah);
1316
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001317 ath_detach(sc);
1318 free_irq(sc->irq, sc);
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001319 ath_bus_cleanup(common);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001320 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001321 ieee80211_free_hw(sc->hw);
1322}
1323
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001324void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301325{
1326 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001327 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05301328 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301329
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301330 ath9k_ps_wakeup(sc);
1331
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001332 dev_dbg(sc->dev, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301333
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001334 ath_deinit_leds(sc);
Sujithe31f7b92009-09-23 13:49:12 +05301335 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001336
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001337 for (i = 0; i < sc->num_sec_wiphy; i++) {
1338 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1339 if (aphy == NULL)
1340 continue;
1341 sc->sec_wiphy[i] = NULL;
1342 ieee80211_unregister_hw(aphy->hw);
1343 ieee80211_free_hw(aphy->hw);
1344 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301345 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301346 ath_rx_cleanup(sc);
1347 ath_tx_cleanup(sc);
1348
Sujith9c84b792008-10-29 10:17:13 +05301349 tasklet_kill(&sc->intr_tq);
1350 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301351
Sujith9c84b792008-10-29 10:17:13 +05301352 if (!(sc->sc_flags & SC_OP_INVALID))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001353 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301354
Sujith9c84b792008-10-29 10:17:13 +05301355 /* cleanup tx queues */
1356 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1357 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301358 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301359
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001360 if ((sc->btcoex.no_stomp_timer) &&
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001361 ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001362 ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301363
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001364 ath9k_hw_detach(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001365 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001366 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301367}
1368
Bob Copelande3bb2492009-03-30 22:30:30 -04001369static int ath9k_reg_notifier(struct wiphy *wiphy,
1370 struct regulatory_request *request)
1371{
1372 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1373 struct ath_wiphy *aphy = hw->priv;
1374 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001375 struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
Bob Copelande3bb2492009-03-30 22:30:30 -04001376
1377 return ath_reg_notifier_apply(wiphy, request, reg);
1378}
1379
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001380/*
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001381 * Detects if there is any priority bt traffic
1382 */
1383static void ath_detect_bt_priority(struct ath_softc *sc)
1384{
1385 struct ath_btcoex *btcoex = &sc->btcoex;
1386 struct ath_hw *ah = sc->sc_ah;
1387
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001388 if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001389 btcoex->bt_priority_cnt++;
1390
1391 if (time_after(jiffies, btcoex->bt_priority_time +
1392 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
1393 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001394 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
1395 "BT priority traffic detected");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001396 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1397 } else {
1398 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
1399 }
1400
1401 btcoex->bt_priority_cnt = 0;
1402 btcoex->bt_priority_time = jiffies;
1403 }
1404}
1405
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001406/*
1407 * Configures appropriate weight based on stomp type.
1408 */
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001409static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
1410 enum ath_stomp_type stomp_type)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001411{
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001412 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001413
1414 switch (stomp_type) {
1415 case ATH_BTCOEX_STOMP_ALL:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001416 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1417 AR_STOMP_ALL_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001418 break;
1419 case ATH_BTCOEX_STOMP_LOW:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001420 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1421 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001422 break;
1423 case ATH_BTCOEX_STOMP_NONE:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001424 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1425 AR_STOMP_NONE_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001426 break;
1427 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001428 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
1429 "Invalid Stomptype\n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001430 break;
1431 }
1432
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001433 ath9k_hw_btcoex_enable(ah);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001434}
1435
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001436static void ath9k_gen_timer_start(struct ath_hw *ah,
1437 struct ath_gen_timer *timer,
1438 u32 timer_next,
1439 u32 timer_period)
1440{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001441 struct ath_common *common = ath9k_hw_common(ah);
1442 struct ath_softc *sc = (struct ath_softc *) common->priv;
1443
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001444 ath9k_hw_gen_timer_start(ah, timer, timer_next, timer_period);
1445
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001446 if ((sc->imask & ATH9K_INT_GENTIMER) == 0) {
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001447 ath9k_hw_set_interrupts(ah, 0);
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001448 sc->imask |= ATH9K_INT_GENTIMER;
1449 ath9k_hw_set_interrupts(ah, sc->imask);
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001450 }
1451}
1452
1453static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
1454{
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001455 struct ath_common *common = ath9k_hw_common(ah);
1456 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001457 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
1458
1459 ath9k_hw_gen_timer_stop(ah, timer);
1460
1461 /* if no timer is enabled, turn off interrupt mask */
1462 if (timer_table->timer_mask.val == 0) {
1463 ath9k_hw_set_interrupts(ah, 0);
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001464 sc->imask &= ~ATH9K_INT_GENTIMER;
1465 ath9k_hw_set_interrupts(ah, sc->imask);
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001466 }
1467}
1468
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001469/*
1470 * This is the master bt coex timer which runs for every
1471 * 45ms, bt traffic will be given priority during 55% of this
1472 * period while wlan gets remaining 45%
1473 */
1474static void ath_btcoex_period_timer(unsigned long data)
1475{
1476 struct ath_softc *sc = (struct ath_softc *) data;
1477 struct ath_hw *ah = sc->sc_ah;
1478 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001479
1480 ath_detect_bt_priority(sc);
1481
1482 spin_lock_bh(&btcoex->btcoex_lock);
1483
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001484 ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001485
1486 spin_unlock_bh(&btcoex->btcoex_lock);
1487
1488 if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1489 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001490 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001491
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001492 ath9k_gen_timer_start(ah,
1493 btcoex->no_stomp_timer,
1494 (ath9k_hw_gettsf32(ah) +
1495 btcoex->btcoex_no_stomp),
1496 btcoex->btcoex_no_stomp * 10);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001497 btcoex->hw_timer_enabled = true;
1498 }
1499
1500 mod_timer(&btcoex->period_timer, jiffies +
1501 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
1502}
1503
1504/*
1505 * Generic tsf based hw timer which configures weight
1506 * registers to time slice between wlan and bt traffic
1507 */
1508static void ath_btcoex_no_stomp_timer(void *arg)
1509{
1510 struct ath_softc *sc = (struct ath_softc *)arg;
1511 struct ath_hw *ah = sc->sc_ah;
1512 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001513
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001514 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
1515 "no stomp timer running \n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001516
1517 spin_lock_bh(&btcoex->btcoex_lock);
1518
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001519 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001520 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001521 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001522 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001523
1524 spin_unlock_bh(&btcoex->btcoex_lock);
1525}
1526
1527static int ath_init_btcoex_timer(struct ath_softc *sc)
1528{
1529 struct ath_btcoex *btcoex = &sc->btcoex;
1530
1531 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
1532 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
1533 btcoex->btcoex_period / 100;
1534
1535 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
1536 (unsigned long) sc);
1537
1538 spin_lock_init(&btcoex->btcoex_lock);
1539
1540 btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
1541 ath_btcoex_no_stomp_timer,
1542 ath_btcoex_no_stomp_timer,
1543 (void *) sc, AR_FIRST_NDP_TIMER);
1544
1545 if (!btcoex->no_stomp_timer)
1546 return -ENOMEM;
1547
1548 return 0;
1549}
1550
1551/*
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001552 * Read and write, they both share the same lock. We do this to serialize
1553 * reads and writes on Atheros 802.11n PCI devices only. This is required
1554 * as the FIFO on these devices can only accept sanely 2 requests. After
1555 * that the device goes bananas. Serializing the reads/writes prevents this
1556 * from happening.
1557 */
1558
1559static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
1560{
1561 struct ath_hw *ah = (struct ath_hw *) hw_priv;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001562 struct ath_common *common = ath9k_hw_common(ah);
1563 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001564
1565 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1566 unsigned long flags;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001567 spin_lock_irqsave(&sc->sc_serial_rw, flags);
1568 iowrite32(val, sc->mem + reg_offset);
1569 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001570 } else
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001571 iowrite32(val, sc->mem + reg_offset);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001572}
1573
1574static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
1575{
1576 struct ath_hw *ah = (struct ath_hw *) hw_priv;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001577 struct ath_common *common = ath9k_hw_common(ah);
1578 struct ath_softc *sc = (struct ath_softc *) common->priv;
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001579 u32 val;
1580
1581 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1582 unsigned long flags;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001583 spin_lock_irqsave(&sc->sc_serial_rw, flags);
1584 val = ioread32(sc->mem + reg_offset);
1585 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001586 } else
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001587 val = ioread32(sc->mem + reg_offset);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001588 return val;
1589}
1590
Luis R. Rodriguez2ddb5c82009-09-14 02:09:38 -07001591static const struct ath_ops ath9k_common_ops = {
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001592 .read = ath9k_ioread32,
1593 .write = ath9k_iowrite32,
1594};
1595
1596/*
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001597 * Initialize and fill ath_softc, ath_sofct is the
1598 * "Software Carrier" struct. Historically it has existed
1599 * to allow the separation between hardware specific
1600 * variables (now in ath_hw) and driver specific variables.
1601 */
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001602static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
1603 const struct ath_bus_ops *bus_ops)
Sujithff37e332008-11-24 12:07:55 +05301604{
Sujithcbe61d82009-02-09 13:27:12 +05301605 struct ath_hw *ah = NULL;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001606 struct ath_common *common;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001607 int r = 0, i;
Sujithff37e332008-11-24 12:07:55 +05301608 int csz = 0;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001609 int qnum;
Sujithff37e332008-11-24 12:07:55 +05301610
1611 /* XXX: hardware will not be ready until ath_open() being called */
1612 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301613
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001614 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301615 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001616 spin_lock_init(&sc->sc_serial_rw);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05301617 spin_lock_init(&sc->ani_lock);
Gabor Juhos04717cc2009-07-14 20:17:13 -04001618 spin_lock_init(&sc->sc_pm_lock);
Sujithaa33de02008-12-18 11:40:16 +05301619 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301620 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301621 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301622 (unsigned long)sc);
1623
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001624 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1625 if (!ah) {
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001626 r = -ENOMEM;
1627 goto bad_no_ah;
1628 }
1629
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -07001630 ah->hw_version.devid = devid;
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301631 ah->hw_version.subsysid = subsysid;
Luis R. Rodrigueze1e2f932009-08-03 12:24:38 -07001632 sc->sc_ah = ah;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001633
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001634 common = ath9k_hw_common(ah);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001635 common->ops = &ath9k_common_ops;
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001636 common->bus_ops = bus_ops;
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001637 common->ah = ah;
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -07001638 common->hw = sc->hw;
Luis R. Rodriguezbc974f42009-09-28 02:54:40 -04001639 common->priv = sc;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001640
1641 /*
1642 * Cache line size is used to size and align various
1643 * structures used to communicate with the hardware.
1644 */
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001645 ath_read_cachesize(common, &csz);
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001646 /* XXX assert csz is non-zero */
1647 common->cachelsz = csz << 2; /* convert to bytes */
1648
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001649 if (ath9k_init_debug(ah) < 0)
1650 dev_err(sc->dev, "Unable to create debugfs files\n");
1651
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001652 r = ath9k_hw_init(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001653 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001654 ath_print(common, ATH_DBG_FATAL,
1655 "Unable to initialize hardware; "
1656 "initialization status: %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301657 goto bad;
1658 }
Sujithff37e332008-11-24 12:07:55 +05301659
1660 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301661 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301662 if (sc->keymax > ATH_KEYMAX) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001663 ath_print(common, ATH_DBG_ANY,
1664 "Warning, using only %u entries in %u key cache\n",
1665 ATH_KEYMAX, sc->keymax);
Sujith17d79042009-02-09 13:27:03 +05301666 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301667 }
1668
1669 /*
1670 * Reset the key cache since some parts do not
1671 * reset the contents on initial power up.
1672 */
Sujith17d79042009-02-09 13:27:03 +05301673 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301674 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301675
Sujithff37e332008-11-24 12:07:55 +05301676 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301677 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001678
Sujithff37e332008-11-24 12:07:55 +05301679 /* Setup rate tables */
1680
1681 ath_rate_attach(sc);
1682 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1683 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1684
1685 /*
1686 * Allocate hardware transmit queues: one queue for
1687 * beacon frames and one data queue for each QoS
1688 * priority. Note that the hal handles reseting
1689 * these queues at the needed time.
1690 */
Sujithb77f4832008-12-07 21:44:03 +05301691 sc->beacon.beaconq = ath_beaconq_setup(ah);
1692 if (sc->beacon.beaconq == -1) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001693 ath_print(common, ATH_DBG_FATAL,
1694 "Unable to setup a beacon xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001695 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301696 goto bad2;
1697 }
Sujithb77f4832008-12-07 21:44:03 +05301698 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1699 if (sc->beacon.cabq == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001700 ath_print(common, ATH_DBG_FATAL,
1701 "Unable to setup CAB xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001702 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301703 goto bad2;
1704 }
1705
Sujith17d79042009-02-09 13:27:03 +05301706 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301707 ath_cabq_update(sc);
1708
Sujithb77f4832008-12-07 21:44:03 +05301709 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1710 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301711
1712 /* Setup data queues */
1713 /* NB: ensure BK queue is the lowest priority h/w queue */
1714 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001715 ath_print(common, ATH_DBG_FATAL,
1716 "Unable to setup xmit queue for BK traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001717 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301718 goto bad2;
1719 }
1720
1721 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001722 ath_print(common, ATH_DBG_FATAL,
1723 "Unable to setup xmit queue for BE traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001724 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301725 goto bad2;
1726 }
1727 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001728 ath_print(common, ATH_DBG_FATAL,
1729 "Unable to setup xmit queue for VI traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001730 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301731 goto bad2;
1732 }
1733 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001734 ath_print(common, ATH_DBG_FATAL,
1735 "Unable to setup xmit queue for VO traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001736 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301737 goto bad2;
1738 }
1739
1740 /* Initializes the noise floor to a reasonable default value.
1741 * Later on this will be updated during ANI processing. */
1742
Sujith17d79042009-02-09 13:27:03 +05301743 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1744 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301745
1746 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1747 ATH9K_CIPHER_TKIP, NULL)) {
1748 /*
1749 * Whether we should enable h/w TKIP MIC.
1750 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1751 * report WMM capable, so it's always safe to turn on
1752 * TKIP MIC in this case.
1753 */
1754 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1755 0, 1, NULL);
1756 }
1757
1758 /*
1759 * Check whether the separate key cache entries
1760 * are required to handle both tx+rx MIC keys.
1761 * With split mic keys the number of stations is limited
1762 * to 27 otherwise 59.
1763 */
1764 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1765 ATH9K_CIPHER_TKIP, NULL)
1766 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1767 ATH9K_CIPHER_MIC, NULL)
1768 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1769 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301770 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301771
1772 /* turn on mcast key search if possible */
1773 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1774 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1775 1, NULL);
1776
Sujith17d79042009-02-09 13:27:03 +05301777 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301778
1779 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301780 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301781 sc->sc_flags |= SC_OP_TXAGGR;
1782 sc->sc_flags |= SC_OP_RXAGGR;
1783 }
1784
Luis R. Rodriguez43c27612009-09-13 21:07:07 -07001785 common->tx_chainmask = ah->caps.tx_chainmask;
1786 common->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301787
1788 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301789 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301790
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001791 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001792 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301793
Sujithb77f4832008-12-07 21:44:03 +05301794 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301795
1796 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001797 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001798 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001799 sc->beacon.bslot_aphy[i] = NULL;
1800 }
Sujithff37e332008-11-24 12:07:55 +05301801
Sujithff37e332008-11-24 12:07:55 +05301802 /* setup channels and rates */
1803
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001804 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301805 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1806 sc->rates[IEEE80211_BAND_2GHZ];
1807 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001808 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1809 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301810
Sujith2660b812009-02-09 13:27:26 +05301811 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001812 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301813 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1814 sc->rates[IEEE80211_BAND_5GHZ];
1815 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001816 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1817 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301818 }
1819
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001820 switch (ah->btcoex_hw.scheme) {
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001821 case ATH_BTCOEX_CFG_NONE:
1822 break;
1823 case ATH_BTCOEX_CFG_2WIRE:
1824 ath9k_hw_btcoex_init_2wire(ah);
1825 break;
1826 case ATH_BTCOEX_CFG_3WIRE:
1827 ath9k_hw_btcoex_init_3wire(ah);
1828 r = ath_init_btcoex_timer(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301829 if (r)
1830 goto bad2;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001831 qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001832 ath9k_hw_init_btcoex_hw(ah, qnum);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001833 sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001834 break;
1835 default:
1836 WARN_ON(1);
1837 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301838 }
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301839
Sujithff37e332008-11-24 12:07:55 +05301840 return 0;
1841bad2:
1842 /* cleanup tx queues */
1843 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1844 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301845 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301846bad:
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001847 ath9k_hw_detach(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001848bad_no_ah:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001849 ath9k_exit_debug(sc->sc_ah);
1850 sc->sc_ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301851
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001852 return r;
Sujithff37e332008-11-24 12:07:55 +05301853}
1854
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001855void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301856{
Sujith9c84b792008-10-29 10:17:13 +05301857 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1858 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1859 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301860 IEEE80211_HW_AMPDU_AGGREGATION |
1861 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301862 IEEE80211_HW_PS_NULLFUNC_STACK |
1863 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301864
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001865 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001866 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1867
Sujith9c84b792008-10-29 10:17:13 +05301868 hw->wiphy->interface_modes =
1869 BIT(NL80211_IFTYPE_AP) |
1870 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001871 BIT(NL80211_IFTYPE_ADHOC) |
1872 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301873
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301874 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301875 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301876 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001877 hw->max_listen_interval = 10;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001878 /* Hardware supports 10 but we use 4 */
1879 hw->max_rate_tries = 4;
Sujith528f0c62008-10-29 10:14:26 +05301880 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301881 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301882
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301883 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301884
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001885 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1886 &sc->sbands[IEEE80211_BAND_2GHZ];
1887 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1888 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1889 &sc->sbands[IEEE80211_BAND_5GHZ];
1890}
1891
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001892/* Device driver core initialization */
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001893int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
1894 const struct ath_bus_ops *bus_ops)
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001895{
1896 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001897 struct ath_common *common;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001898 struct ath_hw *ah;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001899 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001900 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001901
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001902 dev_dbg(sc->dev, "Attach ATH hw\n");
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001903
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001904 error = ath_init_softc(devid, sc, subsysid, bus_ops);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001905 if (error != 0)
1906 return error;
1907
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001908 ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001909 common = ath9k_hw_common(ah);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001910
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001911 /* get mac address from hardware and set in mac80211 */
1912
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001913 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001914
1915 ath_set_hw_capab(sc, hw);
1916
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001917 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001918 ath9k_reg_notifier);
1919 if (error)
1920 return error;
1921
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001922 reg = &common->regulatory;
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001923
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001924 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301925 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001926 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301927 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301928 }
1929
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301930 /* initialize tx/rx engine */
1931 error = ath_tx_init(sc, ATH_TXBUF);
1932 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301933 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301934
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301935 error = ath_rx_init(sc, ATH_RXBUF);
1936 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301937 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301938
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001939 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001940 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1941 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001942
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301943 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301944
Bob Copeland3a702e42009-03-30 22:30:29 -04001945 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001946 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001947 if (error)
1948 goto error_attach;
1949 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001950
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301951 /* Initialize LED control */
1952 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301953
Johannes Berg3b319aa2009-06-13 14:50:26 +05301954 ath_start_rfkill_poll(sc);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001955
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301956 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301957
1958error_attach:
1959 /* cleanup tx queues */
1960 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1961 if (ATH_TXQ_SETUP(sc, i))
1962 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1963
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001964 ath9k_hw_detach(ah);
1965 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001966 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301967
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301968 return error;
1969}
1970
Sujithff37e332008-11-24 12:07:55 +05301971int ath_reset(struct ath_softc *sc, bool retry_tx)
1972{
Sujithcbe61d82009-02-09 13:27:12 +05301973 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001974 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001975 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001976 int r;
Sujithff37e332008-11-24 12:07:55 +05301977
1978 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301979 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301980 ath_stoprecv(sc);
1981 ath_flushrecv(sc);
1982
1983 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301984 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001985 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001986 ath_print(common, ATH_DBG_FATAL,
1987 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301988 spin_unlock_bh(&sc->sc_resetlock);
1989
1990 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001991 ath_print(common, ATH_DBG_FATAL,
1992 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301993
1994 /*
1995 * We may be doing a reset in response to a request
1996 * that changes the channel so update any state that
1997 * might change as a result.
1998 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001999 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302000
2001 ath_update_txpow(sc);
2002
2003 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002004 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05302005
Sujith17d79042009-02-09 13:27:03 +05302006 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302007
2008 if (retry_tx) {
2009 int i;
2010 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2011 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05302012 spin_lock_bh(&sc->tx.txq[i].axq_lock);
2013 ath_txq_schedule(sc, &sc->tx.txq[i]);
2014 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05302015 }
2016 }
2017 }
2018
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002019 return r;
Sujithff37e332008-11-24 12:07:55 +05302020}
2021
2022/*
2023 * This function will allocate both the DMA descriptor structure, and the
2024 * buffers it contains. These are used to contain the descriptors used
2025 * by the system.
2026*/
2027int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
2028 struct list_head *head, const char *name,
2029 int nbuf, int ndesc)
2030{
2031#define DS2PHYS(_dd, _ds) \
2032 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
2033#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
2034#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002035 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithff37e332008-11-24 12:07:55 +05302036 struct ath_desc *ds;
2037 struct ath_buf *bf;
2038 int i, bsize, error;
2039
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002040 ath_print(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
2041 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05302042
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05302043 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05302044 /* ath_desc must be a multiple of DWORDs */
2045 if ((sizeof(struct ath_desc) % 4) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002046 ath_print(common, ATH_DBG_FATAL,
2047 "ath_desc not DWORD aligned\n");
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002048 BUG_ON((sizeof(struct ath_desc) % 4) != 0);
Sujithff37e332008-11-24 12:07:55 +05302049 error = -ENOMEM;
2050 goto fail;
2051 }
2052
Sujithff37e332008-11-24 12:07:55 +05302053 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
2054
2055 /*
2056 * Need additional DMA memory because we can't use
2057 * descriptors that cross the 4K page boundary. Assume
2058 * one skipped descriptor per 4K page.
2059 */
Sujith2660b812009-02-09 13:27:26 +05302060 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05302061 u32 ndesc_skipped =
2062 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
2063 u32 dma_len;
2064
2065 while (ndesc_skipped) {
2066 dma_len = ndesc_skipped * sizeof(struct ath_desc);
2067 dd->dd_desc_len += dma_len;
2068
2069 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
2070 };
2071 }
2072
2073 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01002074 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302075 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302076 if (dd->dd_desc == NULL) {
2077 error = -ENOMEM;
2078 goto fail;
2079 }
2080 ds = dd->dd_desc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002081 ath_print(common, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
2082 name, ds, (u32) dd->dd_desc_len,
2083 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujithff37e332008-11-24 12:07:55 +05302084
2085 /* allocate buffers */
2086 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302087 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302088 if (bf == NULL) {
2089 error = -ENOMEM;
2090 goto fail2;
2091 }
Sujithff37e332008-11-24 12:07:55 +05302092 dd->dd_bufptr = bf;
2093
Sujithff37e332008-11-24 12:07:55 +05302094 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
2095 bf->bf_desc = ds;
2096 bf->bf_daddr = DS2PHYS(dd, ds);
2097
Sujith2660b812009-02-09 13:27:26 +05302098 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05302099 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
2100 /*
2101 * Skip descriptor addresses which can cause 4KB
2102 * boundary crossing (addr + length) with a 32 dword
2103 * descriptor fetch.
2104 */
2105 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
Luis R. Rodriguez9680e8a2009-09-13 23:28:00 -07002106 BUG_ON((caddr_t) bf->bf_desc >=
Sujithff37e332008-11-24 12:07:55 +05302107 ((caddr_t) dd->dd_desc +
2108 dd->dd_desc_len));
2109
2110 ds += ndesc;
2111 bf->bf_desc = ds;
2112 bf->bf_daddr = DS2PHYS(dd, ds);
2113 }
2114 }
2115 list_add_tail(&bf->list, head);
2116 }
2117 return 0;
2118fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01002119 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2120 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302121fail:
2122 memset(dd, 0, sizeof(*dd));
2123 return error;
2124#undef ATH_DESC_4KB_BOUND_CHECK
2125#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
2126#undef DS2PHYS
2127}
2128
2129void ath_descdma_cleanup(struct ath_softc *sc,
2130 struct ath_descdma *dd,
2131 struct list_head *head)
2132{
Gabor Juhos7da3c552009-01-14 20:17:03 +01002133 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2134 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302135
2136 INIT_LIST_HEAD(head);
2137 kfree(dd->dd_bufptr);
2138 memset(dd, 0, sizeof(*dd));
2139}
2140
2141int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
2142{
2143 int qnum;
2144
2145 switch (queue) {
2146 case 0:
Sujithb77f4832008-12-07 21:44:03 +05302147 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05302148 break;
2149 case 1:
Sujithb77f4832008-12-07 21:44:03 +05302150 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05302151 break;
2152 case 2:
Sujithb77f4832008-12-07 21:44:03 +05302153 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302154 break;
2155 case 3:
Sujithb77f4832008-12-07 21:44:03 +05302156 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05302157 break;
2158 default:
Sujithb77f4832008-12-07 21:44:03 +05302159 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302160 break;
2161 }
2162
2163 return qnum;
2164}
2165
2166int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
2167{
2168 int qnum;
2169
2170 switch (queue) {
2171 case ATH9K_WME_AC_VO:
2172 qnum = 0;
2173 break;
2174 case ATH9K_WME_AC_VI:
2175 qnum = 1;
2176 break;
2177 case ATH9K_WME_AC_BE:
2178 qnum = 2;
2179 break;
2180 case ATH9K_WME_AC_BK:
2181 qnum = 3;
2182 break;
2183 default:
2184 qnum = -1;
2185 break;
2186 }
2187
2188 return qnum;
2189}
2190
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002191/* XXX: Remove me once we don't depend on ath9k_channel for all
2192 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002193void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
2194 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002195{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002196 struct ieee80211_channel *chan = hw->conf.channel;
2197 struct ieee80211_conf *conf = &hw->conf;
2198
2199 ichan->channel = chan->center_freq;
2200 ichan->chan = chan;
2201
2202 if (chan->band == IEEE80211_BAND_2GHZ) {
2203 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05302204 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002205 } else {
2206 ichan->chanmode = CHANNEL_A;
2207 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
2208 }
2209
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07002210 if (conf_is_ht(conf))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002211 ichan->chanmode = ath_get_extchanmode(sc, chan,
2212 conf->channel_type);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002213}
2214
Sujithff37e332008-11-24 12:07:55 +05302215/**********************/
2216/* mac80211 callbacks */
2217/**********************/
2218
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002219/*
2220 * (Re)start btcoex timers
2221 */
2222static void ath9k_btcoex_timer_resume(struct ath_softc *sc)
2223{
2224 struct ath_btcoex *btcoex = &sc->btcoex;
2225 struct ath_hw *ah = sc->sc_ah;
2226
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002227 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
2228 "Starting btcoex timers");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002229
2230 /* make sure duty cycle timer is also stopped when resuming */
2231 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002232 ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002233
2234 btcoex->bt_priority_cnt = 0;
2235 btcoex->bt_priority_time = jiffies;
2236 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
2237
2238 mod_timer(&btcoex->period_timer, jiffies);
2239}
2240
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002241static int ath9k_start(struct ieee80211_hw *hw)
2242{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002243 struct ath_wiphy *aphy = hw->priv;
2244 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002245 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002246 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002247 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05302248 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302249 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002250
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002251 ath_print(common, ATH_DBG_CONFIG,
2252 "Starting driver with initial channel: %d MHz\n",
2253 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002254
Sujith141b38b2009-02-04 08:10:07 +05302255 mutex_lock(&sc->mutex);
2256
Jouni Malinen9580a222009-03-03 19:23:33 +02002257 if (ath9k_wiphy_started(sc)) {
2258 if (sc->chan_idx == curchan->hw_value) {
2259 /*
2260 * Already on the operational channel, the new wiphy
2261 * can be marked active.
2262 */
2263 aphy->state = ATH_WIPHY_ACTIVE;
2264 ieee80211_wake_queues(hw);
2265 } else {
2266 /*
2267 * Another wiphy is on another channel, start the new
2268 * wiphy in paused state.
2269 */
2270 aphy->state = ATH_WIPHY_PAUSED;
2271 ieee80211_stop_queues(hw);
2272 }
2273 mutex_unlock(&sc->mutex);
2274 return 0;
2275 }
2276 aphy->state = ATH_WIPHY_ACTIVE;
2277
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002278 /* setup initial channel */
2279
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302280 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002281
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302282 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002283
Sujithff37e332008-11-24 12:07:55 +05302284 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002285 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05302286
2287 /*
2288 * The basic interface to setting the hardware in a good
2289 * state is ``reset''. On return the hardware is known to
2290 * be powered up and with interrupts disabled. This must
2291 * be followed by initialization of the appropriate bits
2292 * and then setup of the interrupt mask.
2293 */
2294 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002295 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002296 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002297 ath_print(common, ATH_DBG_FATAL,
2298 "Unable to reset hardware; reset status %d "
2299 "(freq %u MHz)\n", r,
2300 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05302301 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05302302 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002303 }
Sujithff37e332008-11-24 12:07:55 +05302304 spin_unlock_bh(&sc->sc_resetlock);
2305
2306 /*
2307 * This is needed only to setup initial state
2308 * but it's best done after a reset.
2309 */
2310 ath_update_txpow(sc);
2311
2312 /*
2313 * Setup the hardware after reset:
2314 * The receive engine is set going.
2315 * Frame transmit is handled entirely
2316 * in the frame output path; there's nothing to do
2317 * here except setup the interrupt mask.
2318 */
2319 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002320 ath_print(common, ATH_DBG_FATAL,
2321 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05302322 r = -EIO;
2323 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05302324 }
2325
2326 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05302327 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05302328 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2329 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2330
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002331 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05302332 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05302333
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002334 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302335 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302336
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002337 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302338
2339 sc->sc_flags &= ~SC_OP_INVALID;
2340
2341 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302342 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002343 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302344
Jouni Malinenbce048d2009-03-03 19:23:28 +02002345 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002346
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002347 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002348
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002349 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
2350 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07002351 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
2352 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002353 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05302354
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07002355 if (common->bus_ops->bt_coex_prep)
2356 common->bus_ops->bt_coex_prep(common);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002357 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002358 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302359 }
2360
Sujith141b38b2009-02-04 08:10:07 +05302361mutex_unlock:
2362 mutex_unlock(&sc->mutex);
2363
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002364 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002365}
2366
2367static int ath9k_tx(struct ieee80211_hw *hw,
2368 struct sk_buff *skb)
2369{
Jouni Malinen147583c2008-08-11 14:01:50 +03002370 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002371 struct ath_wiphy *aphy = hw->priv;
2372 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002373 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05302374 struct ath_tx_control txctl;
2375 int hdrlen, padsize;
2376
Jouni Malinen8089cc42009-03-03 19:23:38 +02002377 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002378 ath_print(common, ATH_DBG_XMIT,
2379 "ath9k: %s: TX in unexpected wiphy state "
2380 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02002381 goto exit;
2382 }
2383
Gabor Juhos96148322009-07-24 17:27:21 +02002384 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03002385 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2386 /*
2387 * mac80211 does not set PM field for normal data frames, so we
2388 * need to update that based on the current PS mode.
2389 */
2390 if (ieee80211_is_data(hdr->frame_control) &&
2391 !ieee80211_is_nullfunc(hdr->frame_control) &&
2392 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002393 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
2394 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03002395 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2396 }
2397 }
2398
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002399 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2400 /*
2401 * We are using PS-Poll and mac80211 can request TX while in
2402 * power save mode. Need to wake up hardware for the TX to be
2403 * completed and if needed, also for RX of buffered frames.
2404 */
2405 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2406 ath9k_ps_wakeup(sc);
2407 ath9k_hw_setrxabort(sc->sc_ah, 0);
2408 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002409 ath_print(common, ATH_DBG_PS,
2410 "Sending PS-Poll to pick a buffered frame\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002411 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2412 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002413 ath_print(common, ATH_DBG_PS,
2414 "Wake up to complete TX\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002415 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2416 }
2417 /*
2418 * The actual restore operation will happen only after
2419 * the sc_flags bit is cleared. We are just dropping
2420 * the ps_usecount here.
2421 */
2422 ath9k_ps_restore(sc);
2423 }
2424
Sujith528f0c62008-10-29 10:14:26 +05302425 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002426
2427 /*
2428 * As a temporary workaround, assign seq# here; this will likely need
2429 * to be cleaned up to work better with Beacon transmission and virtual
2430 * BSSes.
2431 */
2432 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2433 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2434 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302435 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002436 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302437 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002438 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002439
2440 /* Add the padding after the header if this is not already done */
2441 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2442 if (hdrlen & 3) {
2443 padsize = hdrlen % 4;
2444 if (skb_headroom(skb) < padsize)
2445 return -1;
2446 skb_push(skb, padsize);
2447 memmove(skb->data, skb->data + padsize, hdrlen);
2448 }
2449
Sujith528f0c62008-10-29 10:14:26 +05302450 /* Check if a tx queue is available */
2451
2452 txctl.txq = ath_test_get_txq(sc, skb);
2453 if (!txctl.txq)
2454 goto exit;
2455
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002456 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002457
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002458 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002459 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302460 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002461 }
2462
2463 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302464exit:
2465 dev_kfree_skb_any(skb);
2466 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467}
2468
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002469/*
2470 * Pause btcoex timer and bt duty cycle timer
2471 */
2472static void ath9k_btcoex_timer_pause(struct ath_softc *sc)
2473{
2474 struct ath_btcoex *btcoex = &sc->btcoex;
2475 struct ath_hw *ah = sc->sc_ah;
2476
2477 del_timer_sync(&btcoex->period_timer);
2478
2479 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002480 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002481
2482 btcoex->hw_timer_enabled = false;
2483}
2484
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002485static void ath9k_stop(struct ieee80211_hw *hw)
2486{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002487 struct ath_wiphy *aphy = hw->priv;
2488 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002489 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002490 struct ath_common *common = ath9k_hw_common(ah);
Sujith9c84b792008-10-29 10:17:13 +05302491
Sujith4c483812009-08-18 10:51:52 +05302492 mutex_lock(&sc->mutex);
2493
Jouni Malinen9580a222009-03-03 19:23:33 +02002494 aphy->state = ATH_WIPHY_INACTIVE;
2495
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07002496 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2497 cancel_delayed_work_sync(&sc->tx_complete_work);
2498
2499 if (!sc->num_sec_wiphy) {
2500 cancel_delayed_work_sync(&sc->wiphy_work);
2501 cancel_work_sync(&sc->chan_work);
2502 }
2503
Sujith9c84b792008-10-29 10:17:13 +05302504 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002505 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05302506 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05302507 return;
2508 }
2509
Jouni Malinen9580a222009-03-03 19:23:33 +02002510 if (ath9k_wiphy_started(sc)) {
2511 mutex_unlock(&sc->mutex);
2512 return; /* another wiphy still in use */
2513 }
2514
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002515 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002516 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002517 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002518 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302519 }
2520
Sujithff37e332008-11-24 12:07:55 +05302521 /* make sure h/w will not generate any interrupt
2522 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002523 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05302524
2525 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302526 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302527 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002528 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05302529 } else
Sujithb77f4832008-12-07 21:44:03 +05302530 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302531
Sujithff37e332008-11-24 12:07:55 +05302532 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002533 ath9k_hw_disable(ah);
2534 ath9k_hw_configpcipowersave(ah, 1, 1);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002535 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05302536
2537 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002538
Sujith141b38b2009-02-04 08:10:07 +05302539 mutex_unlock(&sc->mutex);
2540
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002541 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002542}
2543
2544static int ath9k_add_interface(struct ieee80211_hw *hw,
2545 struct ieee80211_if_init_conf *conf)
2546{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002547 struct ath_wiphy *aphy = hw->priv;
2548 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002549 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith17d79042009-02-09 13:27:03 +05302550 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002551 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002552 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002553
Sujith141b38b2009-02-04 08:10:07 +05302554 mutex_lock(&sc->mutex);
2555
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002556 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2557 sc->nvifs > 0) {
2558 ret = -ENOBUFS;
2559 goto out;
2560 }
2561
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002562 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002563 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002564 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002565 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002566 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002567 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002568 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002569 if (sc->nbcnvifs >= ATH_BCBUF) {
2570 ret = -ENOBUFS;
2571 goto out;
2572 }
Pat Erley9cb54122009-03-20 22:59:59 -04002573 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002574 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002575 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002576 ath_print(common, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302577 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002578 ret = -EOPNOTSUPP;
2579 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002580 }
2581
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002582 ath_print(common, ATH_DBG_CONFIG,
2583 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002584
Sujith17d79042009-02-09 13:27:03 +05302585 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302586 avp->av_opmode = ic_opmode;
2587 avp->av_bslot = -1;
2588
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002589 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002590
2591 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2592 ath9k_set_bssid_mask(hw);
2593
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002594 if (sc->nvifs > 1)
2595 goto out; /* skip global settings for secondary vif */
2596
Sujithb238e902009-03-03 10:16:56 +05302597 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302598 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302599 sc->sc_flags |= SC_OP_TSF_RESET;
2600 }
Sujith5640b082008-10-29 10:16:06 +05302601
Sujith5640b082008-10-29 10:16:06 +05302602 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302603 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302604
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302605 /*
2606 * Enable MIB interrupts when there are hardware phy counters.
2607 * Note we only do this (at the moment) for station mode.
2608 */
Sujith4af9cf42009-02-12 10:06:47 +05302609 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002610 (conf->type == NL80211_IFTYPE_ADHOC) ||
2611 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05302612 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05302613 sc->imask |= ATH9K_INT_TSFOOR;
2614 }
2615
Sujith17d79042009-02-09 13:27:03 +05302616 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302617
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05302618 if (conf->type == NL80211_IFTYPE_AP ||
2619 conf->type == NL80211_IFTYPE_ADHOC ||
2620 conf->type == NL80211_IFTYPE_MONITOR)
Sujith415f7382009-04-13 21:56:46 +05302621 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002622
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002623out:
Sujith141b38b2009-02-04 08:10:07 +05302624 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002625 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626}
2627
2628static void ath9k_remove_interface(struct ieee80211_hw *hw,
2629 struct ieee80211_if_init_conf *conf)
2630{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002631 struct ath_wiphy *aphy = hw->priv;
2632 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002633 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith17d79042009-02-09 13:27:03 +05302634 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002635 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002637 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638
Sujith141b38b2009-02-04 08:10:07 +05302639 mutex_lock(&sc->mutex);
2640
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002641 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302642 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002644 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002645 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2646 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2647 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302648 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649 ath_beacon_return(sc, avp);
2650 }
2651
Sujith672840a2008-08-11 14:05:08 +05302652 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002654 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2655 if (sc->beacon.bslot[i] == conf->vif) {
2656 printk(KERN_DEBUG "%s: vif had allocated beacon "
2657 "slot\n", __func__);
2658 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002659 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002660 }
2661 }
2662
Sujith17d79042009-02-09 13:27:03 +05302663 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302664
2665 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002666}
2667
Johannes Berge8975582008-10-09 12:18:51 +02002668static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002669{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002670 struct ath_wiphy *aphy = hw->priv;
2671 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002672 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berge8975582008-10-09 12:18:51 +02002673 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302674 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002675 bool all_wiphys_idle = false, disable_radio = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002676
Sujithaa33de02008-12-18 11:40:16 +05302677 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302678
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002679 /* Leave this as the first check */
2680 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2681
2682 spin_lock_bh(&sc->wiphy_lock);
2683 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2684 spin_unlock_bh(&sc->wiphy_lock);
2685
2686 if (conf->flags & IEEE80211_CONF_IDLE){
2687 if (all_wiphys_idle)
2688 disable_radio = true;
2689 }
2690 else if (all_wiphys_idle) {
2691 ath_radio_enable(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002692 ath_print(common, ATH_DBG_CONFIG,
2693 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002694 }
2695 }
2696
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302697 if (changed & IEEE80211_CONF_CHANGE_PS) {
2698 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302699 if (!(ah->caps.hw_caps &
2700 ATH9K_HW_CAP_AUTOSLEEP)) {
2701 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2702 sc->imask |= ATH9K_INT_TIM_TIMER;
2703 ath9k_hw_set_interrupts(sc->sc_ah,
2704 sc->imask);
2705 }
2706 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302707 }
Gabor Juhos96148322009-07-24 17:27:21 +02002708 sc->ps_enabled = true;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302709 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02002710 sc->ps_enabled = false;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002711 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302712 if (!(ah->caps.hw_caps &
2713 ATH9K_HW_CAP_AUTOSLEEP)) {
2714 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002715 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2716 SC_OP_WAIT_FOR_CAB |
2717 SC_OP_WAIT_FOR_PSPOLL_DATA |
2718 SC_OP_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302719 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2720 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2721 ath9k_hw_set_interrupts(sc->sc_ah,
2722 sc->imask);
2723 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302724 }
2725 }
2726 }
2727
Johannes Berg47979382009-01-07 10:13:27 +01002728 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302729 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002730 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002731
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002732 aphy->chan_idx = pos;
2733 aphy->chan_is_ht = conf_is_ht(conf);
2734
Jouni Malinen8089cc42009-03-03 19:23:38 +02002735 if (aphy->state == ATH_WIPHY_SCAN ||
2736 aphy->state == ATH_WIPHY_ACTIVE)
2737 ath9k_wiphy_pause_all_forced(sc, aphy);
2738 else {
2739 /*
2740 * Do not change operational channel based on a paused
2741 * wiphy changes.
2742 */
2743 goto skip_chan_change;
2744 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002745
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002746 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
2747 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002748
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002749 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002750 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302751
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002752 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302753
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002754 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002755 ath_print(common, ATH_DBG_FATAL,
2756 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302757 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302758 return -EINVAL;
2759 }
Sujith094d05d2008-12-12 11:57:43 +05302760 }
Sujith86b89ee2008-08-07 10:54:57 +05302761
Jouni Malinen8089cc42009-03-03 19:23:38 +02002762skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002763 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302764 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002765
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002766 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002767 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002768 ath_radio_disable(sc);
2769 }
2770
Sujithaa33de02008-12-18 11:40:16 +05302771 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302772
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002773 return 0;
2774}
2775
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002776#define SUPPORTED_FILTERS \
2777 (FIF_PROMISC_IN_BSS | \
2778 FIF_ALLMULTI | \
2779 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04002780 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002781 FIF_OTHER_BSS | \
2782 FIF_BCN_PRBRESP_PROMISC | \
2783 FIF_FCSFAIL)
2784
Sujith7dcfdcd2008-08-11 14:03:13 +05302785/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002786static void ath9k_configure_filter(struct ieee80211_hw *hw,
2787 unsigned int changed_flags,
2788 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002789 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002790{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002791 struct ath_wiphy *aphy = hw->priv;
2792 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302793 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002794
2795 changed_flags &= SUPPORTED_FILTERS;
2796 *total_flags &= SUPPORTED_FILTERS;
2797
Sujithb77f4832008-12-07 21:44:03 +05302798 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002799 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302800 rfilt = ath_calcrxfilter(sc);
2801 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002802 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302803
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002804 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
2805 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002806}
2807
2808static void ath9k_sta_notify(struct ieee80211_hw *hw,
2809 struct ieee80211_vif *vif,
2810 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002811 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002812{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002813 struct ath_wiphy *aphy = hw->priv;
2814 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002815
2816 switch (cmd) {
2817 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302818 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002819 break;
2820 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302821 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002822 break;
2823 default:
2824 break;
2825 }
2826}
2827
Sujith141b38b2009-02-04 08:10:07 +05302828static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002829 const struct ieee80211_tx_queue_params *params)
2830{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002831 struct ath_wiphy *aphy = hw->priv;
2832 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002833 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05302834 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002835 int ret = 0, qnum;
2836
2837 if (queue >= WME_NUM_AC)
2838 return 0;
2839
Sujith141b38b2009-02-04 08:10:07 +05302840 mutex_lock(&sc->mutex);
2841
Sujith1ffb0612009-03-30 15:28:46 +05302842 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2843
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002844 qi.tqi_aifs = params->aifs;
2845 qi.tqi_cwmin = params->cw_min;
2846 qi.tqi_cwmax = params->cw_max;
2847 qi.tqi_burstTime = params->txop;
2848 qnum = ath_get_hal_qnum(queue, sc);
2849
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002850 ath_print(common, ATH_DBG_CONFIG,
2851 "Configure tx [queue/halq] [%d/%d], "
2852 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
2853 queue, qnum, params->aifs, params->cw_min,
2854 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002855
2856 ret = ath_txq_update(sc, qnum, &qi);
2857 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002858 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002859
Sujith141b38b2009-02-04 08:10:07 +05302860 mutex_unlock(&sc->mutex);
2861
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002862 return ret;
2863}
2864
2865static int ath9k_set_key(struct ieee80211_hw *hw,
2866 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002867 struct ieee80211_vif *vif,
2868 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002869 struct ieee80211_key_conf *key)
2870{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002871 struct ath_wiphy *aphy = hw->priv;
2872 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002873 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002874 int ret = 0;
2875
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002876 if (modparam_nohwcrypt)
2877 return -ENOSPC;
2878
Sujith141b38b2009-02-04 08:10:07 +05302879 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302880 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002881 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002882
2883 switch (cmd) {
2884 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002885 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002886 if (ret >= 0) {
2887 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002888 /* push IV and Michael MIC generation to stack */
2889 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302890 if (key->alg == ALG_TKIP)
2891 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002892 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2893 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002894 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002895 }
2896 break;
2897 case DISABLE_KEY:
2898 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002899 break;
2900 default:
2901 ret = -EINVAL;
2902 }
2903
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302904 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302905 mutex_unlock(&sc->mutex);
2906
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002907 return ret;
2908}
2909
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002910static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2911 struct ieee80211_vif *vif,
2912 struct ieee80211_bss_conf *bss_conf,
2913 u32 changed)
2914{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002915 struct ath_wiphy *aphy = hw->priv;
2916 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002917 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002918 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002919 struct ath_vif *avp = (void *)vif->drv_priv;
2920 u32 rfilt = 0;
2921 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002922
Sujith141b38b2009-02-04 08:10:07 +05302923 mutex_lock(&sc->mutex);
2924
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002925 /*
2926 * TODO: Need to decide which hw opmode to use for
2927 * multi-interface cases
2928 * XXX: This belongs into add_interface!
2929 */
2930 if (vif->type == NL80211_IFTYPE_AP &&
2931 ah->opmode != NL80211_IFTYPE_AP) {
2932 ah->opmode = NL80211_IFTYPE_STATION;
2933 ath9k_hw_setopmode(ah);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002934 memcpy(common->curbssid, common->macaddr, ETH_ALEN);
2935 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002936 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002937 /* Request full reset to get hw opmode changed properly */
2938 sc->sc_flags |= SC_OP_FULL_RESET;
2939 }
2940
2941 if ((changed & BSS_CHANGED_BSSID) &&
2942 !is_zero_ether_addr(bss_conf->bssid)) {
2943 switch (vif->type) {
2944 case NL80211_IFTYPE_STATION:
2945 case NL80211_IFTYPE_ADHOC:
2946 case NL80211_IFTYPE_MESH_POINT:
2947 /* Set BSSID */
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002948 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002949 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002950 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002951 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002952
2953 /* Set aggregation protection mode parameters */
2954 sc->config.ath_aggr_prot = 0;
2955
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002956 ath_print(common, ATH_DBG_CONFIG,
2957 "RX filter 0x%x bssid %pM aid 0x%x\n",
2958 rfilt, common->curbssid, common->curaid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002959
2960 /* need to reconfigure the beacon */
2961 sc->sc_flags &= ~SC_OP_BEACONS ;
2962
2963 break;
2964 default:
2965 break;
2966 }
2967 }
2968
2969 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2970 (vif->type == NL80211_IFTYPE_AP) ||
2971 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2972 if ((changed & BSS_CHANGED_BEACON) ||
2973 (changed & BSS_CHANGED_BEACON_ENABLED &&
2974 bss_conf->enable_beacon)) {
2975 /*
2976 * Allocate and setup the beacon frame.
2977 *
2978 * Stop any previous beacon DMA. This may be
2979 * necessary, for example, when an ibss merge
2980 * causes reconfiguration; we may be called
2981 * with beacon transmission active.
2982 */
2983 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2984
2985 error = ath_beacon_alloc(aphy, vif);
2986 if (!error)
2987 ath_beacon_config(sc, vif);
2988 }
2989 }
2990
2991 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2992 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2993 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2994 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2995 ath9k_hw_keysetmac(sc->sc_ah,
2996 (u16)i,
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002997 common->curbssid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002998 }
2999
3000 /* Only legacy IBSS for now */
3001 if (vif->type == NL80211_IFTYPE_ADHOC)
3002 ath_update_chainmask(sc, 0);
3003
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003004 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003005 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
3006 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003007 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05303008 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003009 else
Sujith672840a2008-08-11 14:05:08 +05303010 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003011 }
3012
3013 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003014 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
3015 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003016 if (bss_conf->use_cts_prot &&
3017 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05303018 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003019 else
Sujith672840a2008-08-11 14:05:08 +05303020 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003021 }
3022
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003023 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003024 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003025 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05303026 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003027 }
Sujith141b38b2009-02-04 08:10:07 +05303028
Johannes Berg57c4d7b2009-04-23 16:10:04 +02003029 /*
3030 * The HW TSF has to be reset when the beacon interval changes.
3031 * We set the flag here, and ath_beacon_config_ap() would take this
3032 * into account when it gets called through the subsequent
3033 * config_interface() call - with IFCC_BEACON in the changed field.
3034 */
3035
3036 if (changed & BSS_CHANGED_BEACON_INT) {
3037 sc->sc_flags |= SC_OP_TSF_RESET;
3038 sc->beacon_interval = bss_conf->beacon_int;
3039 }
3040
Sujith141b38b2009-02-04 08:10:07 +05303041 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003042}
3043
3044static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
3045{
3046 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02003047 struct ath_wiphy *aphy = hw->priv;
3048 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003049
Sujith141b38b2009-02-04 08:10:07 +05303050 mutex_lock(&sc->mutex);
3051 tsf = ath9k_hw_gettsf64(sc->sc_ah);
3052 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003053
3054 return tsf;
3055}
3056
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003057static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
3058{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003059 struct ath_wiphy *aphy = hw->priv;
3060 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003061
Sujith141b38b2009-02-04 08:10:07 +05303062 mutex_lock(&sc->mutex);
3063 ath9k_hw_settsf64(sc->sc_ah, tsf);
3064 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003065}
3066
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003067static void ath9k_reset_tsf(struct ieee80211_hw *hw)
3068{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003069 struct ath_wiphy *aphy = hw->priv;
3070 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003071
Sujith141b38b2009-02-04 08:10:07 +05303072 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07003073
3074 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05303075 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07003076 ath9k_ps_restore(sc);
3077
Sujith141b38b2009-02-04 08:10:07 +05303078 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003079}
3080
3081static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05303082 enum ieee80211_ampdu_mlme_action action,
3083 struct ieee80211_sta *sta,
3084 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003085{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003086 struct ath_wiphy *aphy = hw->priv;
3087 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003088 int ret = 0;
3089
3090 switch (action) {
3091 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05303092 if (!(sc->sc_flags & SC_OP_RXAGGR))
3093 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003094 break;
3095 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003096 break;
3097 case IEEE80211_AMPDU_TX_START:
Sujithf83da962009-07-23 15:32:37 +05303098 ath_tx_aggr_start(sc, sta, tid, ssn);
3099 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003100 break;
3101 case IEEE80211_AMPDU_TX_STOP:
Sujithf83da962009-07-23 15:32:37 +05303102 ath_tx_aggr_stop(sc, sta, tid);
Johannes Berg17741cd2008-09-11 00:02:02 +02003103 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003104 break;
Johannes Bergb1720232009-03-23 17:28:39 +01003105 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05303106 ath_tx_aggr_resume(sc, sta, tid);
3107 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003108 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003109 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
3110 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003111 }
3112
3113 return ret;
3114}
3115
Sujith0c98de62009-03-03 10:16:45 +05303116static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
3117{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003118 struct ath_wiphy *aphy = hw->priv;
3119 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303120
Sujith3d832612009-08-21 12:00:28 +05303121 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003122 if (ath9k_wiphy_scanning(sc)) {
3123 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
3124 "same time\n");
3125 /*
3126 * Do not allow the concurrent scanning state for now. This
3127 * could be improved with scanning control moved into ath9k.
3128 */
Sujith3d832612009-08-21 12:00:28 +05303129 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003130 return;
3131 }
3132
3133 aphy->state = ATH_WIPHY_SCAN;
3134 ath9k_wiphy_pause_all_forced(sc, aphy);
3135
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303136 spin_lock_bh(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +05303137 sc->sc_flags |= SC_OP_SCANNING;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303138 spin_unlock_bh(&sc->ani_lock);
Sujith3d832612009-08-21 12:00:28 +05303139 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303140}
3141
3142static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
3143{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003144 struct ath_wiphy *aphy = hw->priv;
3145 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303146
Sujith3d832612009-08-21 12:00:28 +05303147 mutex_lock(&sc->mutex);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303148 spin_lock_bh(&sc->ani_lock);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003149 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05303150 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05303151 sc->sc_flags |= SC_OP_FULL_RESET;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303152 spin_unlock_bh(&sc->ani_lock);
Vivek Natarajand0bec342009-09-02 15:50:55 +05303153 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05303154 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303155}
3156
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003157struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158 .tx = ath9k_tx,
3159 .start = ath9k_start,
3160 .stop = ath9k_stop,
3161 .add_interface = ath9k_add_interface,
3162 .remove_interface = ath9k_remove_interface,
3163 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003164 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003165 .sta_notify = ath9k_sta_notify,
3166 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003167 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003168 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003169 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003170 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003171 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02003172 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05303173 .sw_scan_start = ath9k_sw_scan_start,
3174 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05303175 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003176};
3177
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003178static struct {
3179 u32 version;
3180 const char * name;
3181} ath_mac_bb_names[] = {
3182 { AR_SREV_VERSION_5416_PCI, "5416" },
3183 { AR_SREV_VERSION_5416_PCIE, "5418" },
3184 { AR_SREV_VERSION_9100, "9100" },
3185 { AR_SREV_VERSION_9160, "9160" },
3186 { AR_SREV_VERSION_9280, "9280" },
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303187 { AR_SREV_VERSION_9285, "9285" },
3188 { AR_SREV_VERSION_9287, "9287" }
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003189};
3190
3191static struct {
3192 u16 version;
3193 const char * name;
3194} ath_rf_names[] = {
3195 { 0, "5133" },
3196 { AR_RAD5133_SREV_MAJOR, "5133" },
3197 { AR_RAD5122_SREV_MAJOR, "5122" },
3198 { AR_RAD2133_SREV_MAJOR, "2133" },
3199 { AR_RAD2122_SREV_MAJOR, "2122" }
3200};
3201
3202/*
3203 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3204 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003205const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003206ath_mac_bb_name(u32 mac_bb_version)
3207{
3208 int i;
3209
3210 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3211 if (ath_mac_bb_names[i].version == mac_bb_version) {
3212 return ath_mac_bb_names[i].name;
3213 }
3214 }
3215
3216 return "????";
3217}
3218
3219/*
3220 * Return the RF name. "????" is returned if the RF is unknown.
3221 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003222const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003223ath_rf_name(u16 rf_version)
3224{
3225 int i;
3226
3227 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3228 if (ath_rf_names[i].version == rf_version) {
3229 return ath_rf_names[i].name;
3230 }
3231 }
3232
3233 return "????";
3234}
3235
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003236static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003237{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303238 int error;
3239
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303240 /* Register rate control algorithm */
3241 error = ath_rate_control_register();
3242 if (error != 0) {
3243 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003244 "ath9k: Unable to register rate control "
3245 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303246 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003247 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303248 }
3249
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003250 error = ath9k_debug_create_root();
3251 if (error) {
3252 printk(KERN_ERR
3253 "ath9k: Unable to create debugfs root: %d\n",
3254 error);
3255 goto err_rate_unregister;
3256 }
3257
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003258 error = ath_pci_init();
3259 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003260 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003261 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003262 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003263 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003264 }
3265
Gabor Juhos09329d32009-01-14 20:17:07 +01003266 error = ath_ahb_init();
3267 if (error < 0) {
3268 error = -ENODEV;
3269 goto err_pci_exit;
3270 }
3271
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003272 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003273
Gabor Juhos09329d32009-01-14 20:17:07 +01003274 err_pci_exit:
3275 ath_pci_exit();
3276
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003277 err_remove_root:
3278 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003279 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303280 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003281 err_out:
3282 return error;
3283}
3284module_init(ath9k_init);
3285
3286static void __exit ath9k_exit(void)
3287{
Gabor Juhos09329d32009-01-14 20:17:07 +01003288 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003289 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003290 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003291 ath_rate_control_unregister();
Sujith04bd46382008-11-28 22:18:05 +05303292 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003293}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003294module_exit(ath9k_exit);