blob: f409bbc305354b43b8008a052ee9e79145d97580 [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. Rodrigueza91d75a2009-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. Rodrigueza91d75a2009-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. Rodrigueza91d75a2009-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);
Sujithff37e332008-11-24 12:07:55 +0530302 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800303 struct ieee80211_channel *channel = hw->conf.channel;
304 int r;
Sujithff37e332008-11-24 12:07:55 +0530305
306 if (sc->sc_flags & SC_OP_INVALID)
307 return -EIO;
308
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530309 ath9k_ps_wakeup(sc);
310
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800311 /*
312 * This is only performed if the channel settings have
313 * actually changed.
314 *
315 * To switch channels clear any pending DMA operations;
316 * wait long enough for the RX fifo to drain, reset the
317 * hardware at the new frequency, and then re-enable
318 * the relevant bits of the h/w.
319 */
320 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530321 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800322 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530323
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800324 /* XXX: do not flush receive queue here. We don't want
325 * to flush data frames already in queue because of
326 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530327
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800328 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
329 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530330
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700331 ath_print(common, ATH_DBG_CONFIG,
332 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
333 sc->sc_ah->curchan->channel,
334 channel->center_freq, sc->tx_chan_width);
Sujith99405f92008-11-24 12:08:35 +0530335
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800336 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800337
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800338 r = ath9k_hw_reset(ah, hchan, fastcc);
339 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700340 ath_print(common, ATH_DBG_FATAL,
341 "Unable to reset channel (%u Mhz) "
342 "reset status %d\n",
343 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530344 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200345 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530346 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800347 spin_unlock_bh(&sc->sc_resetlock);
348
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800349 sc->sc_flags &= ~SC_OP_FULL_RESET;
350
351 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700352 ath_print(common, ATH_DBG_FATAL,
353 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200354 r = -EIO;
355 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800356 }
357
358 ath_cache_conf_rate(sc, &hw->conf);
359 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530360 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200361
362 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530363 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200364 return r;
Sujithff37e332008-11-24 12:07:55 +0530365}
366
367/*
368 * This routine performs the periodic noise floor calibration function
369 * that is used to adjust and optimize the chip performance. This
370 * takes environmental changes (location, temperature) into account.
371 * When the task is complete, it reschedules itself depending on the
372 * appropriate interval that was calculated.
373 */
374static void ath_ani_calibrate(unsigned long data)
375{
Sujith20977d32009-02-20 15:13:28 +0530376 struct ath_softc *sc = (struct ath_softc *)data;
377 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700378 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530379 bool longcal = false;
380 bool shortcal = false;
381 bool aniflag = false;
382 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530383 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530384
Sujith20977d32009-02-20 15:13:28 +0530385 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
386 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530387
388 /*
389 * don't calibrate when we're scanning.
390 * we are most likely not on our home channel.
391 */
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530392 spin_lock(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +0530393 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530394 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530395
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300396 /* Only calibrate if awake */
397 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
398 goto set_timer;
399
400 ath9k_ps_wakeup(sc);
401
Sujithff37e332008-11-24 12:07:55 +0530402 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530403 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530404 longcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700405 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530406 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530407 }
408
Sujith17d79042009-02-09 13:27:03 +0530409 /* Short calibration applies only while caldone is false */
410 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530411 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530412 shortcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700413 ath_print(common, ATH_DBG_ANI,
414 "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530415 sc->ani.shortcal_timer = timestamp;
416 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530417 }
418 } else {
Sujith17d79042009-02-09 13:27:03 +0530419 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530420 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530421 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
422 if (sc->ani.caldone)
423 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530424 }
425 }
426
427 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530428 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530429 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530430 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530431 }
432
433 /* Skip all processing if there's nothing to do. */
434 if (longcal || shortcal || aniflag) {
435 /* Call ANI routine if necessary */
436 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530437 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530438
439 /* Perform calibration if necessary */
440 if (longcal || shortcal) {
Sujith379f0442009-04-13 21:56:48 +0530441 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
442 sc->rx_chainmask, longcal);
Sujithff37e332008-11-24 12:07:55 +0530443
Sujith379f0442009-04-13 21:56:48 +0530444 if (longcal)
445 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
446 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530447
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700448 ath_print(common, ATH_DBG_ANI,
449 " calibrate chan %u/%x nf: %d\n",
450 ah->curchan->channel,
451 ah->curchan->channelFlags,
452 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530453 }
454 }
455
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300456 ath9k_ps_restore(sc);
457
Sujith20977d32009-02-20 15:13:28 +0530458set_timer:
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530459 spin_unlock(&sc->ani_lock);
Sujithff37e332008-11-24 12:07:55 +0530460 /*
461 * Set timer interval based on previous results.
462 * The interval must be the shortest necessary to satisfy ANI,
463 * short calibration and long calibration.
464 */
Sujithaac92072008-12-02 18:37:54 +0530465 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530466 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530467 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530468 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530469 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530470
Sujith17d79042009-02-09 13:27:03 +0530471 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530472}
473
Sujith415f7382009-04-13 21:56:46 +0530474static void ath_start_ani(struct ath_softc *sc)
475{
476 unsigned long timestamp = jiffies_to_msecs(jiffies);
477
478 sc->ani.longcal_timer = timestamp;
479 sc->ani.shortcal_timer = timestamp;
480 sc->ani.checkani_timer = timestamp;
481
482 mod_timer(&sc->ani.timer,
483 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
484}
485
Sujithff37e332008-11-24 12:07:55 +0530486/*
487 * Update tx/rx chainmask. For legacy association,
488 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530489 * the chainmask configuration, for bt coexistence, use
490 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530491 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200492void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530493{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700494 struct ath_hw *ah = sc->sc_ah;
495
Sujith3d832612009-08-21 12:00:28 +0530496 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700497 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Sujith2660b812009-02-09 13:27:26 +0530498 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
499 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530500 } else {
Sujith17d79042009-02-09 13:27:03 +0530501 sc->tx_chainmask = 1;
502 sc->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530503 }
504
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700505 ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
506 "tx chmask: %d, rx chmask: %d\n",
507 sc->tx_chainmask, sc->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530508}
509
510static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
511{
512 struct ath_node *an;
513
514 an = (struct ath_node *)sta->drv_priv;
515
Sujith87792ef2009-03-30 15:28:48 +0530516 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530517 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530518 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530519 sta->ht_cap.ampdu_factor);
520 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400521 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530522 }
Sujithff37e332008-11-24 12:07:55 +0530523}
524
525static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
526{
527 struct ath_node *an = (struct ath_node *)sta->drv_priv;
528
529 if (sc->sc_flags & SC_OP_TXAGGR)
530 ath_tx_node_cleanup(sc, an);
531}
532
533static void ath9k_tasklet(unsigned long data)
534{
535 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700536 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700537 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700538
Sujith17d79042009-02-09 13:27:03 +0530539 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530540
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400541 ath9k_ps_wakeup(sc);
542
Sujithff37e332008-11-24 12:07:55 +0530543 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530544 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400545 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530546 return;
Sujithff37e332008-11-24 12:07:55 +0530547 }
548
Sujith063d8be2009-03-30 15:28:49 +0530549 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
550 spin_lock_bh(&sc->rx.rxflushlock);
551 ath_rx_tasklet(sc, 0);
552 spin_unlock_bh(&sc->rx.rxflushlock);
553 }
554
555 if (status & ATH9K_INT_TX)
556 ath_tx_tasklet(sc);
557
Gabor Juhos96148322009-07-24 17:27:21 +0200558 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300559 /*
560 * TSF sync does not look correct; remain awake to sync with
561 * the next Beacon.
562 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700563 ath_print(common, ATH_DBG_PS,
564 "TSFOOR - Sync with next Beacon\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300565 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300566 }
567
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700568 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530569 if (status & ATH9K_INT_GENTIMER)
570 ath_gen_timer_isr(sc->sc_ah);
571
Sujithff37e332008-11-24 12:07:55 +0530572 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700573 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400574 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530575}
576
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100577irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530578{
Sujith063d8be2009-03-30 15:28:49 +0530579#define SCHED_INTR ( \
580 ATH9K_INT_FATAL | \
581 ATH9K_INT_RXORN | \
582 ATH9K_INT_RXEOL | \
583 ATH9K_INT_RX | \
584 ATH9K_INT_TX | \
585 ATH9K_INT_BMISS | \
586 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530587 ATH9K_INT_TSFOOR | \
588 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530589
Sujithff37e332008-11-24 12:07:55 +0530590 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530591 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530592 enum ath9k_int status;
593 bool sched = false;
594
Sujith063d8be2009-03-30 15:28:49 +0530595 /*
596 * The hardware is not ready/present, don't
597 * touch anything. Note this can happen early
598 * on if the IRQ is shared.
599 */
600 if (sc->sc_flags & SC_OP_INVALID)
601 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530602
Sujithff37e332008-11-24 12:07:55 +0530603
Sujith063d8be2009-03-30 15:28:49 +0530604 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530605
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400606 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530607 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530608
Sujith063d8be2009-03-30 15:28:49 +0530609 /*
610 * Figure out the reason(s) for the interrupt. Note
611 * that the hal returns a pseudo-ISR that may include
612 * bits we haven't explicitly enabled so we mask the
613 * value to insure we only process bits we requested.
614 */
615 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
616 status &= sc->imask; /* discard unasked-for bits */
617
618 /*
619 * If there are no status bits set, then this interrupt was not
620 * for me (should have been caught above).
621 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400622 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530623 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530624
625 /* Cache the status */
626 sc->intrstatus = status;
627
628 if (status & SCHED_INTR)
629 sched = true;
630
631 /*
632 * If a FATAL or RXORN interrupt is received, we have to reset the
633 * chip immediately.
634 */
635 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
636 goto chip_reset;
637
638 if (status & ATH9K_INT_SWBA)
639 tasklet_schedule(&sc->bcon_tasklet);
640
641 if (status & ATH9K_INT_TXURN)
642 ath9k_hw_updatetxtriglevel(ah, true);
643
644 if (status & ATH9K_INT_MIB) {
645 /*
646 * Disable interrupts until we service the MIB
647 * interrupt; otherwise it will continue to
648 * fire.
649 */
650 ath9k_hw_set_interrupts(ah, 0);
651 /*
652 * Let the hal handle the event. We assume
653 * it will clear whatever condition caused
654 * the interrupt.
655 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530656 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530657 ath9k_hw_set_interrupts(ah, sc->imask);
658 }
659
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400660 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
661 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530662 /* Clear RxAbort bit so that we can
663 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700664 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400665 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith063d8be2009-03-30 15:28:49 +0530666 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
667 }
Sujith063d8be2009-03-30 15:28:49 +0530668
669chip_reset:
670
Sujith817e11d2008-12-07 21:42:44 +0530671 ath_debug_stat_interrupt(sc, status);
672
Sujithff37e332008-11-24 12:07:55 +0530673 if (sched) {
674 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530675 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530676 tasklet_schedule(&sc->intr_tq);
677 }
678
679 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530680
681#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530682}
683
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530685 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530686 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700687{
688 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700689
690 switch (chan->band) {
691 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530692 switch(channel_type) {
693 case NL80211_CHAN_NO_HT:
694 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700695 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530696 break;
697 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700698 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530699 break;
700 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700701 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530702 break;
703 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700704 break;
705 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530706 switch(channel_type) {
707 case NL80211_CHAN_NO_HT:
708 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700709 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530710 break;
711 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530713 break;
714 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530716 break;
717 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700718 break;
719 default:
720 break;
721 }
722
723 return chanmode;
724}
725
Jouni Malinen6ace2892008-12-17 13:32:17 +0200726static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200727 struct ath9k_keyval *hk, const u8 *addr,
728 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200730 const u8 *key_rxmic;
731 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732
Jouni Malinen6ace2892008-12-17 13:32:17 +0200733 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
734 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735
736 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200737 /*
738 * Group key installation - only two key cache entries are used
739 * regardless of splitmic capability since group key is only
740 * used either for TX or RX.
741 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200742 if (authenticator) {
743 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
744 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
745 } else {
746 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
747 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
748 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200749 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700750 }
Sujith17d79042009-02-09 13:27:03 +0530751 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200752 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700753 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
754 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
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 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200757
758 /* Separate key cache entries for TX and RX */
759
760 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700761 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200762 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
763 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700764 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
765 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700766 return 0;
767 }
768
769 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
770 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200771 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200772}
773
774static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
775{
776 int i;
777
Sujith17d79042009-02-09 13:27:03 +0530778 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
779 if (test_bit(i, sc->keymap) ||
780 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200781 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530782 if (sc->splitmic &&
783 (test_bit(i + 32, sc->keymap) ||
784 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200785 continue; /* At least one part of TKIP key allocated */
786
787 /* Found a free slot for a TKIP key */
788 return i;
789 }
790 return -1;
791}
792
793static int ath_reserve_key_cache_slot(struct ath_softc *sc)
794{
795 int i;
796
797 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530798 if (sc->splitmic) {
799 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
800 if (!test_bit(i, sc->keymap) &&
801 (test_bit(i + 32, sc->keymap) ||
802 test_bit(i + 64, sc->keymap) ||
803 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200804 return i;
Sujith17d79042009-02-09 13:27:03 +0530805 if (!test_bit(i + 32, sc->keymap) &&
806 (test_bit(i, sc->keymap) ||
807 test_bit(i + 64, sc->keymap) ||
808 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200809 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530810 if (!test_bit(i + 64, sc->keymap) &&
811 (test_bit(i , sc->keymap) ||
812 test_bit(i + 32, sc->keymap) ||
813 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200814 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530815 if (!test_bit(i + 64 + 32, sc->keymap) &&
816 (test_bit(i, sc->keymap) ||
817 test_bit(i + 32, sc->keymap) ||
818 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200819 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200820 }
821 } else {
Sujith17d79042009-02-09 13:27:03 +0530822 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
823 if (!test_bit(i, sc->keymap) &&
824 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200825 return i;
Sujith17d79042009-02-09 13:27:03 +0530826 if (test_bit(i, sc->keymap) &&
827 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200828 return i + 64;
829 }
830 }
831
832 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530833 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200834 /* Do not allow slots that could be needed for TKIP group keys
835 * to be used. This limitation could be removed if we know that
836 * TKIP will not be used. */
837 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
838 continue;
Sujith17d79042009-02-09 13:27:03 +0530839 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200840 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
841 continue;
842 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
843 continue;
844 }
845
Sujith17d79042009-02-09 13:27:03 +0530846 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200847 return i; /* Found a free slot for a key */
848 }
849
850 /* No free slot found */
851 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700852}
853
854static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200855 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100856 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700857 struct ieee80211_key_conf *key)
858{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700859 struct ath9k_keyval hk;
860 const u8 *mac = NULL;
861 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200862 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700863
864 memset(&hk, 0, sizeof(hk));
865
866 switch (key->alg) {
867 case ALG_WEP:
868 hk.kv_type = ATH9K_CIPHER_WEP;
869 break;
870 case ALG_TKIP:
871 hk.kv_type = ATH9K_CIPHER_TKIP;
872 break;
873 case ALG_CCMP:
874 hk.kv_type = ATH9K_CIPHER_AES_CCM;
875 break;
876 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200877 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700878 }
879
Jouni Malinen6ace2892008-12-17 13:32:17 +0200880 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700881 memcpy(hk.kv_val, key->key, key->keylen);
882
Jouni Malinen6ace2892008-12-17 13:32:17 +0200883 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
884 /* For now, use the default keys for broadcast keys. This may
885 * need to change with virtual interfaces. */
886 idx = key->keyidx;
887 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100888 if (WARN_ON(!sta))
889 return -EOPNOTSUPP;
890 mac = sta->addr;
891
Jouni Malinen6ace2892008-12-17 13:32:17 +0200892 if (vif->type != NL80211_IFTYPE_AP) {
893 /* Only keyidx 0 should be used with unicast key, but
894 * allow this for client mode for now. */
895 idx = key->keyidx;
896 } else
897 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700898 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100899 if (WARN_ON(!sta))
900 return -EOPNOTSUPP;
901 mac = sta->addr;
902
Jouni Malinen6ace2892008-12-17 13:32:17 +0200903 if (key->alg == ALG_TKIP)
904 idx = ath_reserve_key_cache_slot_tkip(sc);
905 else
906 idx = ath_reserve_key_cache_slot(sc);
907 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200908 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700909 }
910
911 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200912 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
913 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700914 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200915 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700916
917 if (!ret)
918 return -EIO;
919
Sujith17d79042009-02-09 13:27:03 +0530920 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200921 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530922 set_bit(idx + 64, sc->keymap);
923 if (sc->splitmic) {
924 set_bit(idx + 32, sc->keymap);
925 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200926 }
927 }
928
929 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700930}
931
932static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
933{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200934 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
935 if (key->hw_key_idx < IEEE80211_WEP_NKID)
936 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700937
Sujith17d79042009-02-09 13:27:03 +0530938 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200939 if (key->alg != ALG_TKIP)
940 return;
941
Sujith17d79042009-02-09 13:27:03 +0530942 clear_bit(key->hw_key_idx + 64, sc->keymap);
943 if (sc->splitmic) {
944 clear_bit(key->hw_key_idx + 32, sc->keymap);
945 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200946 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700947}
948
Sujitheb2599c2009-01-23 11:20:44 +0530949static void setup_ht_cap(struct ath_softc *sc,
950 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700951{
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530952 u8 tx_streams, rx_streams;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700953
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200954 ht_info->ht_supported = true;
955 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
956 IEEE80211_HT_CAP_SM_PS |
957 IEEE80211_HT_CAP_SGI_40 |
958 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700959
Sujith9e98ac62009-07-23 15:32:34 +0530960 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
961 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530962
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200963 /* set up supported mcs set */
964 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530965 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
966 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
Sujitheb2599c2009-01-23 11:20:44 +0530967
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530968 if (tx_streams != rx_streams) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700969 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
970 "TX streams %d, RX streams: %d\n",
971 tx_streams, rx_streams);
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530972 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
973 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
974 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
Sujitheb2599c2009-01-23 11:20:44 +0530975 }
976
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530977 ht_info->mcs.rx_mask[0] = 0xff;
978 if (rx_streams >= 2)
979 ht_info->mcs.rx_mask[1] = 0xff;
980
981 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700982}
983
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530984static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530985 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530986 struct ieee80211_bss_conf *bss_conf)
987{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700988 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700989 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530990
991 if (bss_conf->assoc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700992 ath_print(common, ATH_DBG_CONFIG,
993 "Bss Info ASSOC %d, bssid: %pM\n",
994 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530995
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530996 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700997 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700998 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300999
Senthil Balasubramanian2664f202009-06-24 18:56:39 +05301000 /*
1001 * Request a re-configuration of Beacon related timers
1002 * on the receipt of the first Beacon frame (i.e.,
1003 * after time sync with the AP).
1004 */
1005 sc->sc_flags |= SC_OP_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301006
1007 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001008 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301009
1010 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +05301011 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301012
Sujith415f7382009-04-13 21:56:46 +05301013 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301014 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001015 ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001016 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05301017 /* Stop ANI */
1018 del_timer_sync(&sc->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301019 }
1020}
1021
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301022/********************************/
1023/* LED functions */
1024/********************************/
1025
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301026static void ath_led_blink_work(struct work_struct *work)
1027{
1028 struct ath_softc *sc = container_of(work, struct ath_softc,
1029 ath_led_blink_work.work);
1030
1031 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
1032 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301033
1034 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
1035 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301036 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301037 else
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301038 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301039 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301040
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001041 ieee80211_queue_delayed_work(sc->hw,
1042 &sc->ath_led_blink_work,
1043 (sc->sc_flags & SC_OP_LED_ON) ?
1044 msecs_to_jiffies(sc->led_off_duration) :
1045 msecs_to_jiffies(sc->led_on_duration));
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301046
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301047 sc->led_on_duration = sc->led_on_cnt ?
1048 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
1049 ATH_LED_ON_DURATION_IDLE;
1050 sc->led_off_duration = sc->led_off_cnt ?
1051 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
1052 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301053 sc->led_on_cnt = sc->led_off_cnt = 0;
1054 if (sc->sc_flags & SC_OP_LED_ON)
1055 sc->sc_flags &= ~SC_OP_LED_ON;
1056 else
1057 sc->sc_flags |= SC_OP_LED_ON;
1058}
1059
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301060static void ath_led_brightness(struct led_classdev *led_cdev,
1061 enum led_brightness brightness)
1062{
1063 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1064 struct ath_softc *sc = led->sc;
1065
1066 switch (brightness) {
1067 case LED_OFF:
1068 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301069 led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301070 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301071 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301072 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301073 if (led->led_type == ATH_LED_RADIO)
1074 sc->sc_flags &= ~SC_OP_LED_ON;
1075 } else {
1076 sc->led_off_cnt++;
1077 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301078 break;
1079 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301080 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301081 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001082 ieee80211_queue_delayed_work(sc->hw,
1083 &sc->ath_led_blink_work, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301084 } else if (led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301085 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301086 sc->sc_flags |= SC_OP_LED_ON;
1087 } else {
1088 sc->led_on_cnt++;
1089 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301090 break;
1091 default:
1092 break;
1093 }
1094}
1095
1096static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1097 char *trigger)
1098{
1099 int ret;
1100
1101 led->sc = sc;
1102 led->led_cdev.name = led->name;
1103 led->led_cdev.default_trigger = trigger;
1104 led->led_cdev.brightness_set = ath_led_brightness;
1105
1106 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1107 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001108 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1109 "Failed to register led:%s", led->name);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301110 else
1111 led->registered = 1;
1112 return ret;
1113}
1114
1115static void ath_unregister_led(struct ath_led *led)
1116{
1117 if (led->registered) {
1118 led_classdev_unregister(&led->led_cdev);
1119 led->registered = 0;
1120 }
1121}
1122
1123static void ath_deinit_leds(struct ath_softc *sc)
1124{
1125 ath_unregister_led(&sc->assoc_led);
1126 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1127 ath_unregister_led(&sc->tx_led);
1128 ath_unregister_led(&sc->rx_led);
1129 ath_unregister_led(&sc->radio_led);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301130 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301131}
1132
1133static void ath_init_leds(struct ath_softc *sc)
1134{
1135 char *trigger;
1136 int ret;
1137
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301138 if (AR_SREV_9287(sc->sc_ah))
1139 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1140 else
1141 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1142
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301143 /* Configure gpio 1 for output */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301144 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301145 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1146 /* LED off, active low */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301147 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301148
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301149 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1150
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301151 trigger = ieee80211_get_radio_led_name(sc->hw);
1152 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001153 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301154 ret = ath_register_led(sc, &sc->radio_led, trigger);
1155 sc->radio_led.led_type = ATH_LED_RADIO;
1156 if (ret)
1157 goto fail;
1158
1159 trigger = ieee80211_get_assoc_led_name(sc->hw);
1160 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001161 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301162 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1163 sc->assoc_led.led_type = ATH_LED_ASSOC;
1164 if (ret)
1165 goto fail;
1166
1167 trigger = ieee80211_get_tx_led_name(sc->hw);
1168 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001169 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301170 ret = ath_register_led(sc, &sc->tx_led, trigger);
1171 sc->tx_led.led_type = ATH_LED_TX;
1172 if (ret)
1173 goto fail;
1174
1175 trigger = ieee80211_get_rx_led_name(sc->hw);
1176 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001177 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301178 ret = ath_register_led(sc, &sc->rx_led, trigger);
1179 sc->rx_led.led_type = ATH_LED_RX;
1180 if (ret)
1181 goto fail;
1182
1183 return;
1184
1185fail:
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001186 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301187 ath_deinit_leds(sc);
1188}
1189
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001190void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301191{
Sujithcbe61d82009-02-09 13:27:12 +05301192 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001193 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001194 struct ieee80211_channel *channel = sc->hw->conf.channel;
1195 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301196
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301197 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301198 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +05301199
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301200 if (!ah->curchan)
1201 ah->curchan = ath_get_curchannel(sc, sc->hw);
1202
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301203 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301204 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001205 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001206 ath_print(common, ATH_DBG_FATAL,
1207 "Unable to reset channel %u (%uMhz) ",
1208 "reset status %d\n",
1209 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301210 }
1211 spin_unlock_bh(&sc->sc_resetlock);
1212
1213 ath_update_txpow(sc);
1214 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001215 ath_print(common, ATH_DBG_FATAL,
1216 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301217 return;
1218 }
1219
1220 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001221 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301222
1223 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301224 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301225
1226 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301227 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301228 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301229 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301230
1231 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301232 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301233}
1234
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001235void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301236{
Sujithcbe61d82009-02-09 13:27:12 +05301237 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001238 struct ieee80211_channel *channel = sc->hw->conf.channel;
1239 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301240
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301241 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301242 ieee80211_stop_queues(sc->hw);
1243
1244 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301245 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1246 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301247
1248 /* Disable interrupts */
1249 ath9k_hw_set_interrupts(ah, 0);
1250
Sujith043a0402009-01-16 21:38:47 +05301251 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301252 ath_stoprecv(sc); /* turn off frame recv */
1253 ath_flushrecv(sc); /* flush recv queue */
1254
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301255 if (!ah->curchan)
1256 ah->curchan = ath_get_curchannel(sc, sc->hw);
1257
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301258 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301259 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001260 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001261 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1262 "Unable to reset channel %u (%uMhz) "
1263 "reset status %d\n",
1264 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301265 }
1266 spin_unlock_bh(&sc->sc_resetlock);
1267
1268 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301269 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301270 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001271 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301272}
1273
Gabor Juhos5077fd32009-03-06 11:17:55 +01001274/*******************/
1275/* Rfkill */
1276/*******************/
1277
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301278static bool ath_is_rfkill_set(struct ath_softc *sc)
1279{
Sujithcbe61d82009-02-09 13:27:12 +05301280 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301281
Sujith2660b812009-02-09 13:27:26 +05301282 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1283 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301284}
1285
Johannes Berg3b319aa2009-06-13 14:50:26 +05301286static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301287{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301288 struct ath_wiphy *aphy = hw->priv;
1289 struct ath_softc *sc = aphy->sc;
1290 bool blocked = !!ath_is_rfkill_set(sc);
1291
1292 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
Johannes Berg19d337d2009-06-02 13:01:37 +02001293}
1294
Johannes Berg3b319aa2009-06-13 14:50:26 +05301295static void ath_start_rfkill_poll(struct ath_softc *sc)
Johannes Berg19d337d2009-06-02 13:01:37 +02001296{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301297 struct ath_hw *ah = sc->sc_ah;
Johannes Berg19d337d2009-06-02 13:01:37 +02001298
Johannes Berg3b319aa2009-06-13 14:50:26 +05301299 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1300 wiphy_rfkill_start_polling(sc->hw->wiphy);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301301}
1302
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001303void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001304{
1305 ath_detach(sc);
1306 free_irq(sc->irq, sc);
1307 ath_bus_cleanup(sc);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001308 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001309 ieee80211_free_hw(sc->hw);
1310}
1311
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001312void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301313{
1314 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001315 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05301316 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301317
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301318 ath9k_ps_wakeup(sc);
1319
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001320 dev_dbg(sc->dev, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301321
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001322 ath_deinit_leds(sc);
Sujithe31f7b92009-09-23 13:49:12 +05301323 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001324
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001325 for (i = 0; i < sc->num_sec_wiphy; i++) {
1326 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1327 if (aphy == NULL)
1328 continue;
1329 sc->sec_wiphy[i] = NULL;
1330 ieee80211_unregister_hw(aphy->hw);
1331 ieee80211_free_hw(aphy->hw);
1332 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301333 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301334 ath_rx_cleanup(sc);
1335 ath_tx_cleanup(sc);
1336
Sujith9c84b792008-10-29 10:17:13 +05301337 tasklet_kill(&sc->intr_tq);
1338 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301339
Sujith9c84b792008-10-29 10:17:13 +05301340 if (!(sc->sc_flags & SC_OP_INVALID))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001341 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301342
Sujith9c84b792008-10-29 10:17:13 +05301343 /* cleanup tx queues */
1344 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1345 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301346 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301347
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001348 if ((sc->btcoex.no_stomp_timer) &&
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001349 ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001350 ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301351
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001352 ath9k_hw_detach(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001353 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001354 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301355}
1356
Bob Copelande3bb2492009-03-30 22:30:30 -04001357static int ath9k_reg_notifier(struct wiphy *wiphy,
1358 struct regulatory_request *request)
1359{
1360 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1361 struct ath_wiphy *aphy = hw->priv;
1362 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001363 struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
Bob Copelande3bb2492009-03-30 22:30:30 -04001364
1365 return ath_reg_notifier_apply(wiphy, request, reg);
1366}
1367
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001368/*
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001369 * Detects if there is any priority bt traffic
1370 */
1371static void ath_detect_bt_priority(struct ath_softc *sc)
1372{
1373 struct ath_btcoex *btcoex = &sc->btcoex;
1374 struct ath_hw *ah = sc->sc_ah;
1375
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001376 if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001377 btcoex->bt_priority_cnt++;
1378
1379 if (time_after(jiffies, btcoex->bt_priority_time +
1380 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
1381 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001382 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_BTCOEX,
1383 "BT priority traffic detected");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001384 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1385 } else {
1386 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
1387 }
1388
1389 btcoex->bt_priority_cnt = 0;
1390 btcoex->bt_priority_time = jiffies;
1391 }
1392}
1393
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001394/*
1395 * Configures appropriate weight based on stomp type.
1396 */
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001397static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
1398 enum ath_stomp_type stomp_type)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001399{
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001400 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001401
1402 switch (stomp_type) {
1403 case ATH_BTCOEX_STOMP_ALL:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001404 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1405 AR_STOMP_ALL_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001406 break;
1407 case ATH_BTCOEX_STOMP_LOW:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001408 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1409 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001410 break;
1411 case ATH_BTCOEX_STOMP_NONE:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001412 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1413 AR_STOMP_NONE_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001414 break;
1415 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001416 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
1417 "Invalid Stomptype\n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001418 break;
1419 }
1420
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001421 ath9k_hw_btcoex_enable(ah);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001422}
1423
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001424static void ath9k_gen_timer_start(struct ath_hw *ah,
1425 struct ath_gen_timer *timer,
1426 u32 timer_next,
1427 u32 timer_period)
1428{
1429 ath9k_hw_gen_timer_start(ah, timer, timer_next, timer_period);
1430
1431 if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) {
1432 ath9k_hw_set_interrupts(ah, 0);
1433 ah->ah_sc->imask |= ATH9K_INT_GENTIMER;
1434 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
1435 }
1436}
1437
1438static void ath9k_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
1439{
1440 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
1441
1442 ath9k_hw_gen_timer_stop(ah, timer);
1443
1444 /* if no timer is enabled, turn off interrupt mask */
1445 if (timer_table->timer_mask.val == 0) {
1446 ath9k_hw_set_interrupts(ah, 0);
1447 ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER;
1448 ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
1449 }
1450}
1451
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001452/*
1453 * This is the master bt coex timer which runs for every
1454 * 45ms, bt traffic will be given priority during 55% of this
1455 * period while wlan gets remaining 45%
1456 */
1457static void ath_btcoex_period_timer(unsigned long data)
1458{
1459 struct ath_softc *sc = (struct ath_softc *) data;
1460 struct ath_hw *ah = sc->sc_ah;
1461 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001462
1463 ath_detect_bt_priority(sc);
1464
1465 spin_lock_bh(&btcoex->btcoex_lock);
1466
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001467 ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001468
1469 spin_unlock_bh(&btcoex->btcoex_lock);
1470
1471 if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1472 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001473 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001474
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07001475 ath9k_gen_timer_start(ah,
1476 btcoex->no_stomp_timer,
1477 (ath9k_hw_gettsf32(ah) +
1478 btcoex->btcoex_no_stomp),
1479 btcoex->btcoex_no_stomp * 10);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001480 btcoex->hw_timer_enabled = true;
1481 }
1482
1483 mod_timer(&btcoex->period_timer, jiffies +
1484 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
1485}
1486
1487/*
1488 * Generic tsf based hw timer which configures weight
1489 * registers to time slice between wlan and bt traffic
1490 */
1491static void ath_btcoex_no_stomp_timer(void *arg)
1492{
1493 struct ath_softc *sc = (struct ath_softc *)arg;
1494 struct ath_hw *ah = sc->sc_ah;
1495 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001496
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001497 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
1498 "no stomp timer running \n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001499
1500 spin_lock_bh(&btcoex->btcoex_lock);
1501
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001502 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001503 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001504 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001505 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001506
1507 spin_unlock_bh(&btcoex->btcoex_lock);
1508}
1509
1510static int ath_init_btcoex_timer(struct ath_softc *sc)
1511{
1512 struct ath_btcoex *btcoex = &sc->btcoex;
1513
1514 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
1515 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
1516 btcoex->btcoex_period / 100;
1517
1518 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
1519 (unsigned long) sc);
1520
1521 spin_lock_init(&btcoex->btcoex_lock);
1522
1523 btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
1524 ath_btcoex_no_stomp_timer,
1525 ath_btcoex_no_stomp_timer,
1526 (void *) sc, AR_FIRST_NDP_TIMER);
1527
1528 if (!btcoex->no_stomp_timer)
1529 return -ENOMEM;
1530
1531 return 0;
1532}
1533
1534/*
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001535 * Read and write, they both share the same lock. We do this to serialize
1536 * reads and writes on Atheros 802.11n PCI devices only. This is required
1537 * as the FIFO on these devices can only accept sanely 2 requests. After
1538 * that the device goes bananas. Serializing the reads/writes prevents this
1539 * from happening.
1540 */
1541
1542static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
1543{
1544 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1545
1546 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1547 unsigned long flags;
1548 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1549 iowrite32(val, ah->ah_sc->mem + reg_offset);
1550 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1551 } else
1552 iowrite32(val, ah->ah_sc->mem + reg_offset);
1553}
1554
1555static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
1556{
1557 struct ath_hw *ah = (struct ath_hw *) hw_priv;
1558 u32 val;
1559
1560 if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
1561 unsigned long flags;
1562 spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
1563 val = ioread32(ah->ah_sc->mem + reg_offset);
1564 spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
1565 } else
1566 val = ioread32(ah->ah_sc->mem + reg_offset);
1567 return val;
1568}
1569
1570static struct ath_ops ath9k_common_ops = {
1571 .read = ath9k_ioread32,
1572 .write = ath9k_iowrite32,
1573};
1574
1575/*
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001576 * Initialize and fill ath_softc, ath_sofct is the
1577 * "Software Carrier" struct. Historically it has existed
1578 * to allow the separation between hardware specific
1579 * variables (now in ath_hw) and driver specific variables.
1580 */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301581static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
Sujithff37e332008-11-24 12:07:55 +05301582{
Sujithcbe61d82009-02-09 13:27:12 +05301583 struct ath_hw *ah = NULL;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001584 struct ath_common *common;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001585 int r = 0, i;
Sujithff37e332008-11-24 12:07:55 +05301586 int csz = 0;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001587 int qnum;
Sujithff37e332008-11-24 12:07:55 +05301588
1589 /* XXX: hardware will not be ready until ath_open() being called */
1590 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301591
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001592 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301593 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001594 spin_lock_init(&sc->sc_serial_rw);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05301595 spin_lock_init(&sc->ani_lock);
Gabor Juhos04717cc2009-07-14 20:17:13 -04001596 spin_lock_init(&sc->sc_pm_lock);
Sujithaa33de02008-12-18 11:40:16 +05301597 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301598 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301599 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301600 (unsigned long)sc);
1601
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001602 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1603 if (!ah) {
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001604 r = -ENOMEM;
1605 goto bad_no_ah;
1606 }
1607
1608 ah->ah_sc = sc;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -07001609 ah->hw_version.devid = devid;
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301610 ah->hw_version.subsysid = subsysid;
Luis R. Rodrigueze1e2f932009-08-03 12:24:38 -07001611 sc->sc_ah = ah;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001612
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001613 common = ath9k_hw_common(ah);
Luis R. Rodriguez9e4bffd2009-09-10 16:11:21 -07001614 common->ops = &ath9k_common_ops;
Luis R. Rodriguez13b81552009-09-10 17:52:45 -07001615 common->ah = ah;
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -07001616 common->hw = sc->hw;
Luis R. Rodriguez27c51f12009-09-10 11:08:14 -07001617
1618 /*
1619 * Cache line size is used to size and align various
1620 * structures used to communicate with the hardware.
1621 */
1622 ath_read_cachesize(sc, &csz);
1623 /* XXX assert csz is non-zero */
1624 common->cachelsz = csz << 2; /* convert to bytes */
1625
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001626 if (ath9k_init_debug(ah) < 0)
1627 dev_err(sc->dev, "Unable to create debugfs files\n");
1628
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001629 r = ath9k_hw_init(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001630 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001631 ath_print(common, ATH_DBG_FATAL,
1632 "Unable to initialize hardware; "
1633 "initialization status: %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301634 goto bad;
1635 }
Sujithff37e332008-11-24 12:07:55 +05301636
1637 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301638 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301639 if (sc->keymax > ATH_KEYMAX) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001640 ath_print(common, ATH_DBG_ANY,
1641 "Warning, using only %u entries in %u key cache\n",
1642 ATH_KEYMAX, sc->keymax);
Sujith17d79042009-02-09 13:27:03 +05301643 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301644 }
1645
1646 /*
1647 * Reset the key cache since some parts do not
1648 * reset the contents on initial power up.
1649 */
Sujith17d79042009-02-09 13:27:03 +05301650 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301651 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301652
Sujithff37e332008-11-24 12:07:55 +05301653 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301654 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001655
Sujithff37e332008-11-24 12:07:55 +05301656 /* Setup rate tables */
1657
1658 ath_rate_attach(sc);
1659 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1660 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1661
1662 /*
1663 * Allocate hardware transmit queues: one queue for
1664 * beacon frames and one data queue for each QoS
1665 * priority. Note that the hal handles reseting
1666 * these queues at the needed time.
1667 */
Sujithb77f4832008-12-07 21:44:03 +05301668 sc->beacon.beaconq = ath_beaconq_setup(ah);
1669 if (sc->beacon.beaconq == -1) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001670 ath_print(common, ATH_DBG_FATAL,
1671 "Unable to setup a beacon xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001672 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301673 goto bad2;
1674 }
Sujithb77f4832008-12-07 21:44:03 +05301675 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1676 if (sc->beacon.cabq == NULL) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001677 ath_print(common, ATH_DBG_FATAL,
1678 "Unable to setup CAB xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001679 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301680 goto bad2;
1681 }
1682
Sujith17d79042009-02-09 13:27:03 +05301683 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301684 ath_cabq_update(sc);
1685
Sujithb77f4832008-12-07 21:44:03 +05301686 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1687 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301688
1689 /* Setup data queues */
1690 /* NB: ensure BK queue is the lowest priority h/w queue */
1691 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001692 ath_print(common, ATH_DBG_FATAL,
1693 "Unable to setup xmit queue for BK traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001694 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301695 goto bad2;
1696 }
1697
1698 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001699 ath_print(common, ATH_DBG_FATAL,
1700 "Unable to setup xmit queue for BE traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001701 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301702 goto bad2;
1703 }
1704 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001705 ath_print(common, ATH_DBG_FATAL,
1706 "Unable to setup xmit queue for VI traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001707 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301708 goto bad2;
1709 }
1710 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001711 ath_print(common, ATH_DBG_FATAL,
1712 "Unable to setup xmit queue for VO traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001713 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301714 goto bad2;
1715 }
1716
1717 /* Initializes the noise floor to a reasonable default value.
1718 * Later on this will be updated during ANI processing. */
1719
Sujith17d79042009-02-09 13:27:03 +05301720 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1721 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301722
1723 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1724 ATH9K_CIPHER_TKIP, NULL)) {
1725 /*
1726 * Whether we should enable h/w TKIP MIC.
1727 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1728 * report WMM capable, so it's always safe to turn on
1729 * TKIP MIC in this case.
1730 */
1731 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1732 0, 1, NULL);
1733 }
1734
1735 /*
1736 * Check whether the separate key cache entries
1737 * are required to handle both tx+rx MIC keys.
1738 * With split mic keys the number of stations is limited
1739 * to 27 otherwise 59.
1740 */
1741 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1742 ATH9K_CIPHER_TKIP, NULL)
1743 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1744 ATH9K_CIPHER_MIC, NULL)
1745 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1746 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301747 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301748
1749 /* turn on mcast key search if possible */
1750 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1751 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1752 1, NULL);
1753
Sujith17d79042009-02-09 13:27:03 +05301754 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301755
1756 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301757 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301758 sc->sc_flags |= SC_OP_TXAGGR;
1759 sc->sc_flags |= SC_OP_RXAGGR;
1760 }
1761
Sujith2660b812009-02-09 13:27:26 +05301762 sc->tx_chainmask = ah->caps.tx_chainmask;
1763 sc->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301764
1765 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301766 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301767
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001768 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001769 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301770
Sujithb77f4832008-12-07 21:44:03 +05301771 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301772
1773 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001774 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001775 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001776 sc->beacon.bslot_aphy[i] = NULL;
1777 }
Sujithff37e332008-11-24 12:07:55 +05301778
Sujithff37e332008-11-24 12:07:55 +05301779 /* setup channels and rates */
1780
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001781 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301782 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1783 sc->rates[IEEE80211_BAND_2GHZ];
1784 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001785 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1786 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301787
Sujith2660b812009-02-09 13:27:26 +05301788 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001789 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301790 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1791 sc->rates[IEEE80211_BAND_5GHZ];
1792 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001793 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1794 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301795 }
1796
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001797 switch (ah->btcoex_hw.scheme) {
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001798 case ATH_BTCOEX_CFG_NONE:
1799 break;
1800 case ATH_BTCOEX_CFG_2WIRE:
1801 ath9k_hw_btcoex_init_2wire(ah);
1802 break;
1803 case ATH_BTCOEX_CFG_3WIRE:
1804 ath9k_hw_btcoex_init_3wire(ah);
1805 r = ath_init_btcoex_timer(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301806 if (r)
1807 goto bad2;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001808 qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001809 ath9k_hw_init_btcoex_hw(ah, qnum);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001810 sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001811 break;
1812 default:
1813 WARN_ON(1);
1814 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301815 }
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301816
Sujithff37e332008-11-24 12:07:55 +05301817 return 0;
1818bad2:
1819 /* cleanup tx queues */
1820 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1821 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301822 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301823bad:
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001824 ath9k_hw_detach(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001825bad_no_ah:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001826 ath9k_exit_debug(sc->sc_ah);
1827 sc->sc_ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301828
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001829 return r;
Sujithff37e332008-11-24 12:07:55 +05301830}
1831
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001832void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301833{
Sujith9c84b792008-10-29 10:17:13 +05301834 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1835 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1836 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301837 IEEE80211_HW_AMPDU_AGGREGATION |
1838 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301839 IEEE80211_HW_PS_NULLFUNC_STACK |
1840 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301841
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001842 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001843 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1844
Sujith9c84b792008-10-29 10:17:13 +05301845 hw->wiphy->interface_modes =
1846 BIT(NL80211_IFTYPE_AP) |
1847 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001848 BIT(NL80211_IFTYPE_ADHOC) |
1849 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301850
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301851 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301852 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301853 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001854 hw->max_listen_interval = 10;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001855 /* Hardware supports 10 but we use 4 */
1856 hw->max_rate_tries = 4;
Sujith528f0c62008-10-29 10:14:26 +05301857 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301858 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301859
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301860 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301861
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001862 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1863 &sc->sbands[IEEE80211_BAND_2GHZ];
1864 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1865 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1866 &sc->sbands[IEEE80211_BAND_5GHZ];
1867}
1868
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001869/* Device driver core initialization */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301870int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001871{
1872 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001873 struct ath_common *common;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001874 struct ath_hw *ah;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001875 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001876 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001877
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001878 dev_dbg(sc->dev, "Attach ATH hw\n");
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001879
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301880 error = ath_init_softc(devid, sc, subsysid);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001881 if (error != 0)
1882 return error;
1883
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001884 ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001885 common = ath9k_hw_common(ah);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001886
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001887 /* get mac address from hardware and set in mac80211 */
1888
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001889 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001890
1891 ath_set_hw_capab(sc, hw);
1892
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001893 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001894 ath9k_reg_notifier);
1895 if (error)
1896 return error;
1897
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001898 reg = &common->regulatory;
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001899
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001900 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301901 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001902 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301903 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301904 }
1905
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301906 /* initialize tx/rx engine */
1907 error = ath_tx_init(sc, ATH_TXBUF);
1908 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301909 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301910
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301911 error = ath_rx_init(sc, ATH_RXBUF);
1912 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301913 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301914
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001915 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001916 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1917 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001918
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301919 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301920
Bob Copeland3a702e42009-03-30 22:30:29 -04001921 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001922 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001923 if (error)
1924 goto error_attach;
1925 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001926
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301927 /* Initialize LED control */
1928 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301929
Johannes Berg3b319aa2009-06-13 14:50:26 +05301930 ath_start_rfkill_poll(sc);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001931
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301932 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301933
1934error_attach:
1935 /* cleanup tx queues */
1936 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1937 if (ATH_TXQ_SETUP(sc, i))
1938 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1939
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001940 ath9k_hw_detach(ah);
1941 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001942 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301943
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301944 return error;
1945}
1946
Sujithff37e332008-11-24 12:07:55 +05301947int ath_reset(struct ath_softc *sc, bool retry_tx)
1948{
Sujithcbe61d82009-02-09 13:27:12 +05301949 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001950 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001951 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001952 int r;
Sujithff37e332008-11-24 12:07:55 +05301953
1954 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301955 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301956 ath_stoprecv(sc);
1957 ath_flushrecv(sc);
1958
1959 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301960 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001961 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001962 ath_print(common, ATH_DBG_FATAL,
1963 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301964 spin_unlock_bh(&sc->sc_resetlock);
1965
1966 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001967 ath_print(common, ATH_DBG_FATAL,
1968 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301969
1970 /*
1971 * We may be doing a reset in response to a request
1972 * that changes the channel so update any state that
1973 * might change as a result.
1974 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001975 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301976
1977 ath_update_txpow(sc);
1978
1979 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001980 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301981
Sujith17d79042009-02-09 13:27:03 +05301982 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301983
1984 if (retry_tx) {
1985 int i;
1986 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1987 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301988 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1989 ath_txq_schedule(sc, &sc->tx.txq[i]);
1990 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301991 }
1992 }
1993 }
1994
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001995 return r;
Sujithff37e332008-11-24 12:07:55 +05301996}
1997
1998/*
1999 * This function will allocate both the DMA descriptor structure, and the
2000 * buffers it contains. These are used to contain the descriptors used
2001 * by the system.
2002*/
2003int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
2004 struct list_head *head, const char *name,
2005 int nbuf, int ndesc)
2006{
2007#define DS2PHYS(_dd, _ds) \
2008 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
2009#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
2010#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002011 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithff37e332008-11-24 12:07:55 +05302012 struct ath_desc *ds;
2013 struct ath_buf *bf;
2014 int i, bsize, error;
2015
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002016 ath_print(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
2017 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05302018
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05302019 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05302020 /* ath_desc must be a multiple of DWORDs */
2021 if ((sizeof(struct ath_desc) % 4) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002022 ath_print(common, ATH_DBG_FATAL,
2023 "ath_desc not DWORD aligned\n");
Sujithff37e332008-11-24 12:07:55 +05302024 ASSERT((sizeof(struct ath_desc) % 4) == 0);
2025 error = -ENOMEM;
2026 goto fail;
2027 }
2028
Sujithff37e332008-11-24 12:07:55 +05302029 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
2030
2031 /*
2032 * Need additional DMA memory because we can't use
2033 * descriptors that cross the 4K page boundary. Assume
2034 * one skipped descriptor per 4K page.
2035 */
Sujith2660b812009-02-09 13:27:26 +05302036 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05302037 u32 ndesc_skipped =
2038 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
2039 u32 dma_len;
2040
2041 while (ndesc_skipped) {
2042 dma_len = ndesc_skipped * sizeof(struct ath_desc);
2043 dd->dd_desc_len += dma_len;
2044
2045 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
2046 };
2047 }
2048
2049 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01002050 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302051 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302052 if (dd->dd_desc == NULL) {
2053 error = -ENOMEM;
2054 goto fail;
2055 }
2056 ds = dd->dd_desc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002057 ath_print(common, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
2058 name, ds, (u32) dd->dd_desc_len,
2059 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujithff37e332008-11-24 12:07:55 +05302060
2061 /* allocate buffers */
2062 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05302063 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05302064 if (bf == NULL) {
2065 error = -ENOMEM;
2066 goto fail2;
2067 }
Sujithff37e332008-11-24 12:07:55 +05302068 dd->dd_bufptr = bf;
2069
Sujithff37e332008-11-24 12:07:55 +05302070 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
2071 bf->bf_desc = ds;
2072 bf->bf_daddr = DS2PHYS(dd, ds);
2073
Sujith2660b812009-02-09 13:27:26 +05302074 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05302075 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
2076 /*
2077 * Skip descriptor addresses which can cause 4KB
2078 * boundary crossing (addr + length) with a 32 dword
2079 * descriptor fetch.
2080 */
2081 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
2082 ASSERT((caddr_t) bf->bf_desc <
2083 ((caddr_t) dd->dd_desc +
2084 dd->dd_desc_len));
2085
2086 ds += ndesc;
2087 bf->bf_desc = ds;
2088 bf->bf_daddr = DS2PHYS(dd, ds);
2089 }
2090 }
2091 list_add_tail(&bf->list, head);
2092 }
2093 return 0;
2094fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01002095 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2096 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302097fail:
2098 memset(dd, 0, sizeof(*dd));
2099 return error;
2100#undef ATH_DESC_4KB_BOUND_CHECK
2101#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
2102#undef DS2PHYS
2103}
2104
2105void ath_descdma_cleanup(struct ath_softc *sc,
2106 struct ath_descdma *dd,
2107 struct list_head *head)
2108{
Gabor Juhos7da3c552009-01-14 20:17:03 +01002109 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2110 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302111
2112 INIT_LIST_HEAD(head);
2113 kfree(dd->dd_bufptr);
2114 memset(dd, 0, sizeof(*dd));
2115}
2116
2117int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
2118{
2119 int qnum;
2120
2121 switch (queue) {
2122 case 0:
Sujithb77f4832008-12-07 21:44:03 +05302123 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05302124 break;
2125 case 1:
Sujithb77f4832008-12-07 21:44:03 +05302126 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05302127 break;
2128 case 2:
Sujithb77f4832008-12-07 21:44:03 +05302129 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302130 break;
2131 case 3:
Sujithb77f4832008-12-07 21:44:03 +05302132 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05302133 break;
2134 default:
Sujithb77f4832008-12-07 21:44:03 +05302135 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302136 break;
2137 }
2138
2139 return qnum;
2140}
2141
2142int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
2143{
2144 int qnum;
2145
2146 switch (queue) {
2147 case ATH9K_WME_AC_VO:
2148 qnum = 0;
2149 break;
2150 case ATH9K_WME_AC_VI:
2151 qnum = 1;
2152 break;
2153 case ATH9K_WME_AC_BE:
2154 qnum = 2;
2155 break;
2156 case ATH9K_WME_AC_BK:
2157 qnum = 3;
2158 break;
2159 default:
2160 qnum = -1;
2161 break;
2162 }
2163
2164 return qnum;
2165}
2166
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002167/* XXX: Remove me once we don't depend on ath9k_channel for all
2168 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002169void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
2170 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002171{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002172 struct ieee80211_channel *chan = hw->conf.channel;
2173 struct ieee80211_conf *conf = &hw->conf;
2174
2175 ichan->channel = chan->center_freq;
2176 ichan->chan = chan;
2177
2178 if (chan->band == IEEE80211_BAND_2GHZ) {
2179 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05302180 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002181 } else {
2182 ichan->chanmode = CHANNEL_A;
2183 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
2184 }
2185
2186 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
2187
2188 if (conf_is_ht(conf)) {
2189 if (conf_is_ht40(conf))
2190 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
2191
2192 ichan->chanmode = ath_get_extchanmode(sc, chan,
2193 conf->channel_type);
2194 }
2195}
2196
Sujithff37e332008-11-24 12:07:55 +05302197/**********************/
2198/* mac80211 callbacks */
2199/**********************/
2200
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002201/*
2202 * (Re)start btcoex timers
2203 */
2204static void ath9k_btcoex_timer_resume(struct ath_softc *sc)
2205{
2206 struct ath_btcoex *btcoex = &sc->btcoex;
2207 struct ath_hw *ah = sc->sc_ah;
2208
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002209 ath_print(ath9k_hw_common(ah), ATH_DBG_BTCOEX,
2210 "Starting btcoex timers");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002211
2212 /* make sure duty cycle timer is also stopped when resuming */
2213 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002214 ath9k_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002215
2216 btcoex->bt_priority_cnt = 0;
2217 btcoex->bt_priority_time = jiffies;
2218 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
2219
2220 mod_timer(&btcoex->period_timer, jiffies);
2221}
2222
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002223static int ath9k_start(struct ieee80211_hw *hw)
2224{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002225 struct ath_wiphy *aphy = hw->priv;
2226 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002227 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002228 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002229 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05302230 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302231 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002232
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002233 ath_print(common, ATH_DBG_CONFIG,
2234 "Starting driver with initial channel: %d MHz\n",
2235 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002236
Sujith141b38b2009-02-04 08:10:07 +05302237 mutex_lock(&sc->mutex);
2238
Jouni Malinen9580a222009-03-03 19:23:33 +02002239 if (ath9k_wiphy_started(sc)) {
2240 if (sc->chan_idx == curchan->hw_value) {
2241 /*
2242 * Already on the operational channel, the new wiphy
2243 * can be marked active.
2244 */
2245 aphy->state = ATH_WIPHY_ACTIVE;
2246 ieee80211_wake_queues(hw);
2247 } else {
2248 /*
2249 * Another wiphy is on another channel, start the new
2250 * wiphy in paused state.
2251 */
2252 aphy->state = ATH_WIPHY_PAUSED;
2253 ieee80211_stop_queues(hw);
2254 }
2255 mutex_unlock(&sc->mutex);
2256 return 0;
2257 }
2258 aphy->state = ATH_WIPHY_ACTIVE;
2259
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002260 /* setup initial channel */
2261
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302262 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002263
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302264 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002265
Sujithff37e332008-11-24 12:07:55 +05302266 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002267 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05302268
2269 /*
2270 * The basic interface to setting the hardware in a good
2271 * state is ``reset''. On return the hardware is known to
2272 * be powered up and with interrupts disabled. This must
2273 * be followed by initialization of the appropriate bits
2274 * and then setup of the interrupt mask.
2275 */
2276 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002277 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002278 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002279 ath_print(common, ATH_DBG_FATAL,
2280 "Unable to reset hardware; reset status %d "
2281 "(freq %u MHz)\n", r,
2282 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05302283 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05302284 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002285 }
Sujithff37e332008-11-24 12:07:55 +05302286 spin_unlock_bh(&sc->sc_resetlock);
2287
2288 /*
2289 * This is needed only to setup initial state
2290 * but it's best done after a reset.
2291 */
2292 ath_update_txpow(sc);
2293
2294 /*
2295 * Setup the hardware after reset:
2296 * The receive engine is set going.
2297 * Frame transmit is handled entirely
2298 * in the frame output path; there's nothing to do
2299 * here except setup the interrupt mask.
2300 */
2301 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002302 ath_print(common, ATH_DBG_FATAL,
2303 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05302304 r = -EIO;
2305 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05302306 }
2307
2308 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05302309 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05302310 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2311 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2312
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002313 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05302314 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05302315
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002316 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302317 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302318
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002319 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302320
2321 sc->sc_flags &= ~SC_OP_INVALID;
2322
2323 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302324 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002325 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302326
Jouni Malinenbce048d2009-03-03 19:23:28 +02002327 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002328
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002329 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002330
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002331 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
2332 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07002333 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
2334 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002335 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05302336
Luis R. Rodriguez867633f2009-09-10 12:12:23 -07002337 if (sc->bus_ops->bt_coex_prep)
2338 sc->bus_ops->bt_coex_prep(sc);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002339 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002340 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302341 }
2342
Sujith141b38b2009-02-04 08:10:07 +05302343mutex_unlock:
2344 mutex_unlock(&sc->mutex);
2345
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002346 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002347}
2348
2349static int ath9k_tx(struct ieee80211_hw *hw,
2350 struct sk_buff *skb)
2351{
Jouni Malinen147583c2008-08-11 14:01:50 +03002352 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002353 struct ath_wiphy *aphy = hw->priv;
2354 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002355 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05302356 struct ath_tx_control txctl;
2357 int hdrlen, padsize;
2358
Jouni Malinen8089cc42009-03-03 19:23:38 +02002359 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002360 ath_print(common, ATH_DBG_XMIT,
2361 "ath9k: %s: TX in unexpected wiphy state "
2362 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02002363 goto exit;
2364 }
2365
Gabor Juhos96148322009-07-24 17:27:21 +02002366 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03002367 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2368 /*
2369 * mac80211 does not set PM field for normal data frames, so we
2370 * need to update that based on the current PS mode.
2371 */
2372 if (ieee80211_is_data(hdr->frame_control) &&
2373 !ieee80211_is_nullfunc(hdr->frame_control) &&
2374 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002375 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
2376 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03002377 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2378 }
2379 }
2380
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002381 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2382 /*
2383 * We are using PS-Poll and mac80211 can request TX while in
2384 * power save mode. Need to wake up hardware for the TX to be
2385 * completed and if needed, also for RX of buffered frames.
2386 */
2387 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2388 ath9k_ps_wakeup(sc);
2389 ath9k_hw_setrxabort(sc->sc_ah, 0);
2390 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002391 ath_print(common, ATH_DBG_PS,
2392 "Sending PS-Poll to pick a buffered frame\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002393 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2394 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002395 ath_print(common, ATH_DBG_PS,
2396 "Wake up to complete TX\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002397 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2398 }
2399 /*
2400 * The actual restore operation will happen only after
2401 * the sc_flags bit is cleared. We are just dropping
2402 * the ps_usecount here.
2403 */
2404 ath9k_ps_restore(sc);
2405 }
2406
Sujith528f0c62008-10-29 10:14:26 +05302407 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002408
2409 /*
2410 * As a temporary workaround, assign seq# here; this will likely need
2411 * to be cleaned up to work better with Beacon transmission and virtual
2412 * BSSes.
2413 */
2414 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2415 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2416 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302417 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002418 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302419 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002420 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002421
2422 /* Add the padding after the header if this is not already done */
2423 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2424 if (hdrlen & 3) {
2425 padsize = hdrlen % 4;
2426 if (skb_headroom(skb) < padsize)
2427 return -1;
2428 skb_push(skb, padsize);
2429 memmove(skb->data, skb->data + padsize, hdrlen);
2430 }
2431
Sujith528f0c62008-10-29 10:14:26 +05302432 /* Check if a tx queue is available */
2433
2434 txctl.txq = ath_test_get_txq(sc, skb);
2435 if (!txctl.txq)
2436 goto exit;
2437
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002438 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002439
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002440 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002441 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302442 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443 }
2444
2445 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302446exit:
2447 dev_kfree_skb_any(skb);
2448 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449}
2450
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002451/*
2452 * Pause btcoex timer and bt duty cycle timer
2453 */
2454static void ath9k_btcoex_timer_pause(struct ath_softc *sc)
2455{
2456 struct ath_btcoex *btcoex = &sc->btcoex;
2457 struct ath_hw *ah = sc->sc_ah;
2458
2459 del_timer_sync(&btcoex->period_timer);
2460
2461 if (btcoex->hw_timer_enabled)
Luis R. Rodriguezcd9bf682009-09-13 02:08:34 -07002462 ath9k_gen_timer_stop(ah, btcoex->no_stomp_timer);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002463
2464 btcoex->hw_timer_enabled = false;
2465}
2466
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002467static void ath9k_stop(struct ieee80211_hw *hw)
2468{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002469 struct ath_wiphy *aphy = hw->priv;
2470 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002471 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002472 struct ath_common *common = ath9k_hw_common(ah);
Sujith9c84b792008-10-29 10:17:13 +05302473
Sujith4c483812009-08-18 10:51:52 +05302474 mutex_lock(&sc->mutex);
2475
Jouni Malinen9580a222009-03-03 19:23:33 +02002476 aphy->state = ATH_WIPHY_INACTIVE;
2477
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07002478 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2479 cancel_delayed_work_sync(&sc->tx_complete_work);
2480
2481 if (!sc->num_sec_wiphy) {
2482 cancel_delayed_work_sync(&sc->wiphy_work);
2483 cancel_work_sync(&sc->chan_work);
2484 }
2485
Sujith9c84b792008-10-29 10:17:13 +05302486 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002487 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05302488 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05302489 return;
2490 }
2491
Jouni Malinen9580a222009-03-03 19:23:33 +02002492 if (ath9k_wiphy_started(sc)) {
2493 mutex_unlock(&sc->mutex);
2494 return; /* another wiphy still in use */
2495 }
2496
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002497 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002498 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002499 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002500 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302501 }
2502
Sujithff37e332008-11-24 12:07:55 +05302503 /* make sure h/w will not generate any interrupt
2504 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002505 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05302506
2507 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302508 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302509 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002510 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05302511 } else
Sujithb77f4832008-12-07 21:44:03 +05302512 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302513
Sujithff37e332008-11-24 12:07:55 +05302514 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002515 ath9k_hw_disable(ah);
2516 ath9k_hw_configpcipowersave(ah, 1, 1);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002517 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05302518
2519 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002520
Sujith141b38b2009-02-04 08:10:07 +05302521 mutex_unlock(&sc->mutex);
2522
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002523 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002524}
2525
2526static int ath9k_add_interface(struct ieee80211_hw *hw,
2527 struct ieee80211_if_init_conf *conf)
2528{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002529 struct ath_wiphy *aphy = hw->priv;
2530 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002531 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith17d79042009-02-09 13:27:03 +05302532 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002533 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002534 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002535
Sujith141b38b2009-02-04 08:10:07 +05302536 mutex_lock(&sc->mutex);
2537
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002538 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2539 sc->nvifs > 0) {
2540 ret = -ENOBUFS;
2541 goto out;
2542 }
2543
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002544 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002545 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002546 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002547 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002548 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002549 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002550 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002551 if (sc->nbcnvifs >= ATH_BCBUF) {
2552 ret = -ENOBUFS;
2553 goto out;
2554 }
Pat Erley9cb54122009-03-20 22:59:59 -04002555 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002556 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002558 ath_print(common, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302559 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002560 ret = -EOPNOTSUPP;
2561 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002562 }
2563
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002564 ath_print(common, ATH_DBG_CONFIG,
2565 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002566
Sujith17d79042009-02-09 13:27:03 +05302567 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302568 avp->av_opmode = ic_opmode;
2569 avp->av_bslot = -1;
2570
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002571 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002572
2573 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2574 ath9k_set_bssid_mask(hw);
2575
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002576 if (sc->nvifs > 1)
2577 goto out; /* skip global settings for secondary vif */
2578
Sujithb238e902009-03-03 10:16:56 +05302579 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302580 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302581 sc->sc_flags |= SC_OP_TSF_RESET;
2582 }
Sujith5640b082008-10-29 10:16:06 +05302583
Sujith5640b082008-10-29 10:16:06 +05302584 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302585 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302586
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302587 /*
2588 * Enable MIB interrupts when there are hardware phy counters.
2589 * Note we only do this (at the moment) for station mode.
2590 */
Sujith4af9cf42009-02-12 10:06:47 +05302591 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002592 (conf->type == NL80211_IFTYPE_ADHOC) ||
2593 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05302594 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05302595 sc->imask |= ATH9K_INT_TSFOOR;
2596 }
2597
Sujith17d79042009-02-09 13:27:03 +05302598 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302599
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05302600 if (conf->type == NL80211_IFTYPE_AP ||
2601 conf->type == NL80211_IFTYPE_ADHOC ||
2602 conf->type == NL80211_IFTYPE_MONITOR)
Sujith415f7382009-04-13 21:56:46 +05302603 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002604
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002605out:
Sujith141b38b2009-02-04 08:10:07 +05302606 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002607 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002608}
2609
2610static void ath9k_remove_interface(struct ieee80211_hw *hw,
2611 struct ieee80211_if_init_conf *conf)
2612{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002613 struct ath_wiphy *aphy = hw->priv;
2614 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002615 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith17d79042009-02-09 13:27:03 +05302616 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002617 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002618
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002619 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002620
Sujith141b38b2009-02-04 08:10:07 +05302621 mutex_lock(&sc->mutex);
2622
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002623 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302624 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002625
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002627 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2628 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2629 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302630 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631 ath_beacon_return(sc, avp);
2632 }
2633
Sujith672840a2008-08-11 14:05:08 +05302634 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002635
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002636 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2637 if (sc->beacon.bslot[i] == conf->vif) {
2638 printk(KERN_DEBUG "%s: vif had allocated beacon "
2639 "slot\n", __func__);
2640 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002641 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002642 }
2643 }
2644
Sujith17d79042009-02-09 13:27:03 +05302645 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302646
2647 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002648}
2649
Johannes Berge8975582008-10-09 12:18:51 +02002650static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002651{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002652 struct ath_wiphy *aphy = hw->priv;
2653 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002654 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berge8975582008-10-09 12:18:51 +02002655 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302656 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002657 bool all_wiphys_idle = false, disable_radio = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002658
Sujithaa33de02008-12-18 11:40:16 +05302659 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302660
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002661 /* Leave this as the first check */
2662 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2663
2664 spin_lock_bh(&sc->wiphy_lock);
2665 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2666 spin_unlock_bh(&sc->wiphy_lock);
2667
2668 if (conf->flags & IEEE80211_CONF_IDLE){
2669 if (all_wiphys_idle)
2670 disable_radio = true;
2671 }
2672 else if (all_wiphys_idle) {
2673 ath_radio_enable(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002674 ath_print(common, ATH_DBG_CONFIG,
2675 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002676 }
2677 }
2678
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302679 if (changed & IEEE80211_CONF_CHANGE_PS) {
2680 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302681 if (!(ah->caps.hw_caps &
2682 ATH9K_HW_CAP_AUTOSLEEP)) {
2683 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2684 sc->imask |= ATH9K_INT_TIM_TIMER;
2685 ath9k_hw_set_interrupts(sc->sc_ah,
2686 sc->imask);
2687 }
2688 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302689 }
Gabor Juhos96148322009-07-24 17:27:21 +02002690 sc->ps_enabled = true;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302691 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02002692 sc->ps_enabled = false;
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07002693 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302694 if (!(ah->caps.hw_caps &
2695 ATH9K_HW_CAP_AUTOSLEEP)) {
2696 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002697 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2698 SC_OP_WAIT_FOR_CAB |
2699 SC_OP_WAIT_FOR_PSPOLL_DATA |
2700 SC_OP_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302701 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2702 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2703 ath9k_hw_set_interrupts(sc->sc_ah,
2704 sc->imask);
2705 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302706 }
2707 }
2708 }
2709
Johannes Berg47979382009-01-07 10:13:27 +01002710 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302711 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002712 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002713
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002714 aphy->chan_idx = pos;
2715 aphy->chan_is_ht = conf_is_ht(conf);
2716
Jouni Malinen8089cc42009-03-03 19:23:38 +02002717 if (aphy->state == ATH_WIPHY_SCAN ||
2718 aphy->state == ATH_WIPHY_ACTIVE)
2719 ath9k_wiphy_pause_all_forced(sc, aphy);
2720 else {
2721 /*
2722 * Do not change operational channel based on a paused
2723 * wiphy changes.
2724 */
2725 goto skip_chan_change;
2726 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002727
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002728 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
2729 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002730
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002731 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002732 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302733
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002734 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302735
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002736 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002737 ath_print(common, ATH_DBG_FATAL,
2738 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302739 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302740 return -EINVAL;
2741 }
Sujith094d05d2008-12-12 11:57:43 +05302742 }
Sujith86b89ee2008-08-07 10:54:57 +05302743
Jouni Malinen8089cc42009-03-03 19:23:38 +02002744skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002745 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302746 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002747
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002748 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002749 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002750 ath_radio_disable(sc);
2751 }
2752
Sujithaa33de02008-12-18 11:40:16 +05302753 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302754
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002755 return 0;
2756}
2757
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002758#define SUPPORTED_FILTERS \
2759 (FIF_PROMISC_IN_BSS | \
2760 FIF_ALLMULTI | \
2761 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04002762 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002763 FIF_OTHER_BSS | \
2764 FIF_BCN_PRBRESP_PROMISC | \
2765 FIF_FCSFAIL)
2766
Sujith7dcfdcd2008-08-11 14:03:13 +05302767/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002768static void ath9k_configure_filter(struct ieee80211_hw *hw,
2769 unsigned int changed_flags,
2770 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002771 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002772{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002773 struct ath_wiphy *aphy = hw->priv;
2774 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302775 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002776
2777 changed_flags &= SUPPORTED_FILTERS;
2778 *total_flags &= SUPPORTED_FILTERS;
2779
Sujithb77f4832008-12-07 21:44:03 +05302780 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002781 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302782 rfilt = ath_calcrxfilter(sc);
2783 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002784 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302785
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002786 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
2787 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002788}
2789
2790static void ath9k_sta_notify(struct ieee80211_hw *hw,
2791 struct ieee80211_vif *vif,
2792 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002793 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002794{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002795 struct ath_wiphy *aphy = hw->priv;
2796 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002797
2798 switch (cmd) {
2799 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302800 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002801 break;
2802 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302803 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002804 break;
2805 default:
2806 break;
2807 }
2808}
2809
Sujith141b38b2009-02-04 08:10:07 +05302810static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002811 const struct ieee80211_tx_queue_params *params)
2812{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002813 struct ath_wiphy *aphy = hw->priv;
2814 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002815 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05302816 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002817 int ret = 0, qnum;
2818
2819 if (queue >= WME_NUM_AC)
2820 return 0;
2821
Sujith141b38b2009-02-04 08:10:07 +05302822 mutex_lock(&sc->mutex);
2823
Sujith1ffb0612009-03-30 15:28:46 +05302824 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2825
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002826 qi.tqi_aifs = params->aifs;
2827 qi.tqi_cwmin = params->cw_min;
2828 qi.tqi_cwmax = params->cw_max;
2829 qi.tqi_burstTime = params->txop;
2830 qnum = ath_get_hal_qnum(queue, sc);
2831
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002832 ath_print(common, ATH_DBG_CONFIG,
2833 "Configure tx [queue/halq] [%d/%d], "
2834 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
2835 queue, qnum, params->aifs, params->cw_min,
2836 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002837
2838 ret = ath_txq_update(sc, qnum, &qi);
2839 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002840 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002841
Sujith141b38b2009-02-04 08:10:07 +05302842 mutex_unlock(&sc->mutex);
2843
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002844 return ret;
2845}
2846
2847static int ath9k_set_key(struct ieee80211_hw *hw,
2848 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002849 struct ieee80211_vif *vif,
2850 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002851 struct ieee80211_key_conf *key)
2852{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002853 struct ath_wiphy *aphy = hw->priv;
2854 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002855 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002856 int ret = 0;
2857
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002858 if (modparam_nohwcrypt)
2859 return -ENOSPC;
2860
Sujith141b38b2009-02-04 08:10:07 +05302861 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302862 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002863 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002864
2865 switch (cmd) {
2866 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002867 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002868 if (ret >= 0) {
2869 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002870 /* push IV and Michael MIC generation to stack */
2871 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302872 if (key->alg == ALG_TKIP)
2873 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002874 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2875 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002876 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 }
2878 break;
2879 case DISABLE_KEY:
2880 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881 break;
2882 default:
2883 ret = -EINVAL;
2884 }
2885
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302886 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302887 mutex_unlock(&sc->mutex);
2888
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002889 return ret;
2890}
2891
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002892static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2893 struct ieee80211_vif *vif,
2894 struct ieee80211_bss_conf *bss_conf,
2895 u32 changed)
2896{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002897 struct ath_wiphy *aphy = hw->priv;
2898 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002899 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002900 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002901 struct ath_vif *avp = (void *)vif->drv_priv;
2902 u32 rfilt = 0;
2903 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002904
Sujith141b38b2009-02-04 08:10:07 +05302905 mutex_lock(&sc->mutex);
2906
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002907 /*
2908 * TODO: Need to decide which hw opmode to use for
2909 * multi-interface cases
2910 * XXX: This belongs into add_interface!
2911 */
2912 if (vif->type == NL80211_IFTYPE_AP &&
2913 ah->opmode != NL80211_IFTYPE_AP) {
2914 ah->opmode = NL80211_IFTYPE_STATION;
2915 ath9k_hw_setopmode(ah);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002916 memcpy(common->curbssid, common->macaddr, ETH_ALEN);
2917 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002918 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002919 /* Request full reset to get hw opmode changed properly */
2920 sc->sc_flags |= SC_OP_FULL_RESET;
2921 }
2922
2923 if ((changed & BSS_CHANGED_BSSID) &&
2924 !is_zero_ether_addr(bss_conf->bssid)) {
2925 switch (vif->type) {
2926 case NL80211_IFTYPE_STATION:
2927 case NL80211_IFTYPE_ADHOC:
2928 case NL80211_IFTYPE_MESH_POINT:
2929 /* Set BSSID */
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002930 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002931 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002932 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07002933 ath9k_hw_write_associd(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002934
2935 /* Set aggregation protection mode parameters */
2936 sc->config.ath_aggr_prot = 0;
2937
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002938 ath_print(common, ATH_DBG_CONFIG,
2939 "RX filter 0x%x bssid %pM aid 0x%x\n",
2940 rfilt, common->curbssid, common->curaid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002941
2942 /* need to reconfigure the beacon */
2943 sc->sc_flags &= ~SC_OP_BEACONS ;
2944
2945 break;
2946 default:
2947 break;
2948 }
2949 }
2950
2951 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2952 (vif->type == NL80211_IFTYPE_AP) ||
2953 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2954 if ((changed & BSS_CHANGED_BEACON) ||
2955 (changed & BSS_CHANGED_BEACON_ENABLED &&
2956 bss_conf->enable_beacon)) {
2957 /*
2958 * Allocate and setup the beacon frame.
2959 *
2960 * Stop any previous beacon DMA. This may be
2961 * necessary, for example, when an ibss merge
2962 * causes reconfiguration; we may be called
2963 * with beacon transmission active.
2964 */
2965 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2966
2967 error = ath_beacon_alloc(aphy, vif);
2968 if (!error)
2969 ath_beacon_config(sc, vif);
2970 }
2971 }
2972
2973 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2974 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2975 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2976 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2977 ath9k_hw_keysetmac(sc->sc_ah,
2978 (u16)i,
Luis R. Rodriguez15107182009-09-10 09:22:37 -07002979 common->curbssid);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002980 }
2981
2982 /* Only legacy IBSS for now */
2983 if (vif->type == NL80211_IFTYPE_ADHOC)
2984 ath_update_chainmask(sc, 0);
2985
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002986 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002987 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
2988 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002989 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302990 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002991 else
Sujith672840a2008-08-11 14:05:08 +05302992 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002993 }
2994
2995 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07002996 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
2997 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002998 if (bss_conf->use_cts_prot &&
2999 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05303000 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003001 else
Sujith672840a2008-08-11 14:05:08 +05303002 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003003 }
3004
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003005 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003006 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003007 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05303008 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003009 }
Sujith141b38b2009-02-04 08:10:07 +05303010
Johannes Berg57c4d7b2009-04-23 16:10:04 +02003011 /*
3012 * The HW TSF has to be reset when the beacon interval changes.
3013 * We set the flag here, and ath_beacon_config_ap() would take this
3014 * into account when it gets called through the subsequent
3015 * config_interface() call - with IFCC_BEACON in the changed field.
3016 */
3017
3018 if (changed & BSS_CHANGED_BEACON_INT) {
3019 sc->sc_flags |= SC_OP_TSF_RESET;
3020 sc->beacon_interval = bss_conf->beacon_int;
3021 }
3022
Sujith141b38b2009-02-04 08:10:07 +05303023 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003024}
3025
3026static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
3027{
3028 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02003029 struct ath_wiphy *aphy = hw->priv;
3030 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003031
Sujith141b38b2009-02-04 08:10:07 +05303032 mutex_lock(&sc->mutex);
3033 tsf = ath9k_hw_gettsf64(sc->sc_ah);
3034 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003035
3036 return tsf;
3037}
3038
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003039static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
3040{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003041 struct ath_wiphy *aphy = hw->priv;
3042 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003043
Sujith141b38b2009-02-04 08:10:07 +05303044 mutex_lock(&sc->mutex);
3045 ath9k_hw_settsf64(sc->sc_ah, tsf);
3046 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003047}
3048
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003049static void ath9k_reset_tsf(struct ieee80211_hw *hw)
3050{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003051 struct ath_wiphy *aphy = hw->priv;
3052 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003053
Sujith141b38b2009-02-04 08:10:07 +05303054 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07003055
3056 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05303057 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07003058 ath9k_ps_restore(sc);
3059
Sujith141b38b2009-02-04 08:10:07 +05303060 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003061}
3062
3063static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05303064 enum ieee80211_ampdu_mlme_action action,
3065 struct ieee80211_sta *sta,
3066 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003067{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003068 struct ath_wiphy *aphy = hw->priv;
3069 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003070 int ret = 0;
3071
3072 switch (action) {
3073 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05303074 if (!(sc->sc_flags & SC_OP_RXAGGR))
3075 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003076 break;
3077 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003078 break;
3079 case IEEE80211_AMPDU_TX_START:
Sujithf83da962009-07-23 15:32:37 +05303080 ath_tx_aggr_start(sc, sta, tid, ssn);
3081 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003082 break;
3083 case IEEE80211_AMPDU_TX_STOP:
Sujithf83da962009-07-23 15:32:37 +05303084 ath_tx_aggr_stop(sc, sta, tid);
Johannes Berg17741cd2008-09-11 00:02:02 +02003085 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003086 break;
Johannes Bergb1720232009-03-23 17:28:39 +01003087 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05303088 ath_tx_aggr_resume(sc, sta, tid);
3089 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003090 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07003091 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
3092 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003093 }
3094
3095 return ret;
3096}
3097
Sujith0c98de62009-03-03 10:16:45 +05303098static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
3099{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003100 struct ath_wiphy *aphy = hw->priv;
3101 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303102
Sujith3d832612009-08-21 12:00:28 +05303103 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003104 if (ath9k_wiphy_scanning(sc)) {
3105 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
3106 "same time\n");
3107 /*
3108 * Do not allow the concurrent scanning state for now. This
3109 * could be improved with scanning control moved into ath9k.
3110 */
Sujith3d832612009-08-21 12:00:28 +05303111 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003112 return;
3113 }
3114
3115 aphy->state = ATH_WIPHY_SCAN;
3116 ath9k_wiphy_pause_all_forced(sc, aphy);
3117
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303118 spin_lock_bh(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +05303119 sc->sc_flags |= SC_OP_SCANNING;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303120 spin_unlock_bh(&sc->ani_lock);
Sujith3d832612009-08-21 12:00:28 +05303121 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303122}
3123
3124static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
3125{
Jouni Malinenbce048d2009-03-03 19:23:28 +02003126 struct ath_wiphy *aphy = hw->priv;
3127 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303128
Sujith3d832612009-08-21 12:00:28 +05303129 mutex_lock(&sc->mutex);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303130 spin_lock_bh(&sc->ani_lock);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003131 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05303132 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05303133 sc->sc_flags |= SC_OP_FULL_RESET;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303134 spin_unlock_bh(&sc->ani_lock);
Vivek Natarajand0bec342009-09-02 15:50:55 +05303135 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05303136 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303137}
3138
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003139struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003140 .tx = ath9k_tx,
3141 .start = ath9k_start,
3142 .stop = ath9k_stop,
3143 .add_interface = ath9k_add_interface,
3144 .remove_interface = ath9k_remove_interface,
3145 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003146 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003147 .sta_notify = ath9k_sta_notify,
3148 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003149 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003150 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003151 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003152 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003153 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02003154 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05303155 .sw_scan_start = ath9k_sw_scan_start,
3156 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05303157 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003158};
3159
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003160static struct {
3161 u32 version;
3162 const char * name;
3163} ath_mac_bb_names[] = {
3164 { AR_SREV_VERSION_5416_PCI, "5416" },
3165 { AR_SREV_VERSION_5416_PCIE, "5418" },
3166 { AR_SREV_VERSION_9100, "9100" },
3167 { AR_SREV_VERSION_9160, "9160" },
3168 { AR_SREV_VERSION_9280, "9280" },
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303169 { AR_SREV_VERSION_9285, "9285" },
3170 { AR_SREV_VERSION_9287, "9287" }
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003171};
3172
3173static struct {
3174 u16 version;
3175 const char * name;
3176} ath_rf_names[] = {
3177 { 0, "5133" },
3178 { AR_RAD5133_SREV_MAJOR, "5133" },
3179 { AR_RAD5122_SREV_MAJOR, "5122" },
3180 { AR_RAD2133_SREV_MAJOR, "2133" },
3181 { AR_RAD2122_SREV_MAJOR, "2122" }
3182};
3183
3184/*
3185 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3186 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003187const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003188ath_mac_bb_name(u32 mac_bb_version)
3189{
3190 int i;
3191
3192 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3193 if (ath_mac_bb_names[i].version == mac_bb_version) {
3194 return ath_mac_bb_names[i].name;
3195 }
3196 }
3197
3198 return "????";
3199}
3200
3201/*
3202 * Return the RF name. "????" is returned if the RF is unknown.
3203 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003204const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003205ath_rf_name(u16 rf_version)
3206{
3207 int i;
3208
3209 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3210 if (ath_rf_names[i].version == rf_version) {
3211 return ath_rf_names[i].name;
3212 }
3213 }
3214
3215 return "????";
3216}
3217
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003218static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003219{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303220 int error;
3221
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303222 /* Register rate control algorithm */
3223 error = ath_rate_control_register();
3224 if (error != 0) {
3225 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003226 "ath9k: Unable to register rate control "
3227 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303228 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003229 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303230 }
3231
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003232 error = ath9k_debug_create_root();
3233 if (error) {
3234 printk(KERN_ERR
3235 "ath9k: Unable to create debugfs root: %d\n",
3236 error);
3237 goto err_rate_unregister;
3238 }
3239
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003240 error = ath_pci_init();
3241 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003242 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003243 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003244 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003245 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003246 }
3247
Gabor Juhos09329d32009-01-14 20:17:07 +01003248 error = ath_ahb_init();
3249 if (error < 0) {
3250 error = -ENODEV;
3251 goto err_pci_exit;
3252 }
3253
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003254 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003255
Gabor Juhos09329d32009-01-14 20:17:07 +01003256 err_pci_exit:
3257 ath_pci_exit();
3258
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003259 err_remove_root:
3260 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003261 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303262 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003263 err_out:
3264 return error;
3265}
3266module_init(ath9k_init);
3267
3268static void __exit ath9k_exit(void)
3269{
Gabor Juhos09329d32009-01-14 20:17:07 +01003270 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003271 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003272 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003273 ath_rate_control_unregister();
Sujith04bd4632008-11-28 22:18:05 +05303274 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003275}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003276module_exit(ath9k_exit);