blob: 9f9ac5b52acb5e542afb22ee4954e7956ef6e52d [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{
Sujithcbe61d8a2009-02-09 13:27:12 +0530143 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530144 u32 txpow;
145
Sujith17d79042009-02-09 13:27:03 +0530146 if (sc->curtxpow != sc->config.txpowlimit) {
147 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +0530148 /* read back in case value is clamped */
149 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
Sujith17d79042009-02-09 13:27:03 +0530150 sc->curtxpow = txpow;
Sujithff37e332008-11-24 12:07:55 +0530151 }
152}
153
154static u8 parse_mpdudensity(u8 mpdudensity)
155{
156 /*
157 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
158 * 0 for no restriction
159 * 1 for 1/4 us
160 * 2 for 1/2 us
161 * 3 for 1 us
162 * 4 for 2 us
163 * 5 for 4 us
164 * 6 for 8 us
165 * 7 for 16 us
166 */
167 switch (mpdudensity) {
168 case 0:
169 return 0;
170 case 1:
171 case 2:
172 case 3:
173 /* Our lower layer calculations limit our precision to
174 1 microsecond */
175 return 1;
176 case 4:
177 return 2;
178 case 5:
179 return 4;
180 case 6:
181 return 8;
182 case 7:
183 return 16;
184 default:
185 return 0;
186 }
187}
188
189static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
190{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400191 const struct ath_rate_table *rate_table = NULL;
Sujithff37e332008-11-24 12:07:55 +0530192 struct ieee80211_supported_band *sband;
193 struct ieee80211_rate *rate;
194 int i, maxrates;
195
196 switch (band) {
197 case IEEE80211_BAND_2GHZ:
198 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
199 break;
200 case IEEE80211_BAND_5GHZ:
201 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
202 break;
203 default:
204 break;
205 }
206
207 if (rate_table == NULL)
208 return;
209
210 sband = &sc->sbands[band];
211 rate = sc->rates[band];
212
213 if (rate_table->rate_cnt > ATH_RATE_MAX)
214 maxrates = ATH_RATE_MAX;
215 else
216 maxrates = rate_table->rate_cnt;
217
218 for (i = 0; i < maxrates; i++) {
219 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
220 rate[i].hw_value = rate_table->info[i].ratecode;
Sujithf46730d2009-01-27 13:51:03 +0530221 if (rate_table->info[i].short_preamble) {
222 rate[i].hw_value_short = rate_table->info[i].ratecode |
223 rate_table->info[i].short_preamble;
224 rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
225 }
Sujithff37e332008-11-24 12:07:55 +0530226 sband->n_bitrates++;
Sujithf46730d2009-01-27 13:51:03 +0530227
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700228 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
Sujith04bd4632008-11-28 22:18:05 +0530229 rate[i].bitrate / 10, rate[i].hw_value);
Sujithff37e332008-11-24 12:07:55 +0530230 }
231}
232
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530233static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
234 struct ieee80211_hw *hw)
235{
236 struct ieee80211_channel *curchan = hw->conf.channel;
237 struct ath9k_channel *channel;
238 u8 chan_idx;
239
240 chan_idx = curchan->hw_value;
241 channel = &sc->sc_ah->channels[chan_idx];
242 ath9k_update_ichannel(sc, hw, channel);
243 return channel;
244}
245
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700246void ath9k_ps_wakeup(struct ath_softc *sc)
247{
248 unsigned long flags;
249
250 spin_lock_irqsave(&sc->sc_pm_lock, flags);
251 if (++sc->ps_usecount != 1)
252 goto unlock;
253
254 ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_AWAKE);
255
256 unlock:
257 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
258}
259
260void ath9k_ps_restore(struct ath_softc *sc)
261{
262 unsigned long flags;
263
264 spin_lock_irqsave(&sc->sc_pm_lock, flags);
265 if (--sc->ps_usecount != 0)
266 goto unlock;
267
268 if (sc->ps_enabled &&
269 !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
270 SC_OP_WAIT_FOR_CAB |
271 SC_OP_WAIT_FOR_PSPOLL_DATA |
272 SC_OP_WAIT_FOR_TX_ACK)))
273 ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
274
275 unlock:
276 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
277}
278
Sujithff37e332008-11-24 12:07:55 +0530279/*
280 * Set/change channels. If the channel is really being changed, it's done
281 * by reseting the chip. To accomplish this we must first cleanup any pending
282 * DMA, then restart stuff.
283*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200284int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
285 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530286{
Sujithcbe61d8a2009-02-09 13:27:12 +0530287 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530288 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800289 struct ieee80211_channel *channel = hw->conf.channel;
290 int r;
Sujithff37e332008-11-24 12:07:55 +0530291
292 if (sc->sc_flags & SC_OP_INVALID)
293 return -EIO;
294
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530295 ath9k_ps_wakeup(sc);
296
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800297 /*
298 * This is only performed if the channel settings have
299 * actually changed.
300 *
301 * To switch channels clear any pending DMA operations;
302 * wait long enough for the RX fifo to drain, reset the
303 * hardware at the new frequency, and then re-enable
304 * the relevant bits of the h/w.
305 */
306 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530307 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800308 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530309
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800310 /* XXX: do not flush receive queue here. We don't want
311 * to flush data frames already in queue because of
312 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530313
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800314 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
315 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530316
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700317 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800318 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
Sujith2660b812009-02-09 13:27:26 +0530319 sc->sc_ah->curchan->channel,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800320 channel->center_freq, sc->tx_chan_width);
Sujith99405f92008-11-24 12:08:35 +0530321
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800322 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800323
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800324 r = ath9k_hw_reset(ah, hchan, fastcc);
325 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700326 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800327 "Unable to reset channel (%u Mhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +0530328 "reset status %d\n",
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800329 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530330 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200331 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530332 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800333 spin_unlock_bh(&sc->sc_resetlock);
334
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800335 sc->sc_flags &= ~SC_OP_FULL_RESET;
336
337 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700338 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800339 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200340 r = -EIO;
341 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800342 }
343
344 ath_cache_conf_rate(sc, &hw->conf);
345 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530346 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200347
348 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530349 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200350 return r;
Sujithff37e332008-11-24 12:07:55 +0530351}
352
353/*
354 * This routine performs the periodic noise floor calibration function
355 * that is used to adjust and optimize the chip performance. This
356 * takes environmental changes (location, temperature) into account.
357 * When the task is complete, it reschedules itself depending on the
358 * appropriate interval that was calculated.
359 */
360static void ath_ani_calibrate(unsigned long data)
361{
Sujith20977d32009-02-20 15:13:28 +0530362 struct ath_softc *sc = (struct ath_softc *)data;
363 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530364 bool longcal = false;
365 bool shortcal = false;
366 bool aniflag = false;
367 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530368 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530369
Sujith20977d32009-02-20 15:13:28 +0530370 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
371 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530372
373 /*
374 * don't calibrate when we're scanning.
375 * we are most likely not on our home channel.
376 */
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530377 spin_lock(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +0530378 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530379 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530380
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300381 /* Only calibrate if awake */
382 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
383 goto set_timer;
384
385 ath9k_ps_wakeup(sc);
386
Sujithff37e332008-11-24 12:07:55 +0530387 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530388 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530389 longcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700390 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530391 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530392 }
393
Sujith17d79042009-02-09 13:27:03 +0530394 /* Short calibration applies only while caldone is false */
395 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530396 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530397 shortcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700398 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530399 sc->ani.shortcal_timer = timestamp;
400 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530401 }
402 } else {
Sujith17d79042009-02-09 13:27:03 +0530403 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530404 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530405 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
406 if (sc->ani.caldone)
407 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530408 }
409 }
410
411 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530412 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530413 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530414 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530415 }
416
417 /* Skip all processing if there's nothing to do. */
418 if (longcal || shortcal || aniflag) {
419 /* Call ANI routine if necessary */
420 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530421 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530422
423 /* Perform calibration if necessary */
424 if (longcal || shortcal) {
Sujith379f0442009-04-13 21:56:48 +0530425 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
426 sc->rx_chainmask, longcal);
Sujithff37e332008-11-24 12:07:55 +0530427
Sujith379f0442009-04-13 21:56:48 +0530428 if (longcal)
429 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
430 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530431
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700432 DPRINTF(sc->sc_ah, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
Sujith379f0442009-04-13 21:56:48 +0530433 ah->curchan->channel, ah->curchan->channelFlags,
434 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530435 }
436 }
437
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300438 ath9k_ps_restore(sc);
439
Sujith20977d32009-02-20 15:13:28 +0530440set_timer:
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530441 spin_unlock(&sc->ani_lock);
Sujithff37e332008-11-24 12:07:55 +0530442 /*
443 * Set timer interval based on previous results.
444 * The interval must be the shortest necessary to satisfy ANI,
445 * short calibration and long calibration.
446 */
Sujithaac92072008-12-02 18:37:54 +0530447 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530448 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530449 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530450 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530451 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530452
Sujith17d79042009-02-09 13:27:03 +0530453 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530454}
455
Sujith415f7382009-04-13 21:56:46 +0530456static void ath_start_ani(struct ath_softc *sc)
457{
458 unsigned long timestamp = jiffies_to_msecs(jiffies);
459
460 sc->ani.longcal_timer = timestamp;
461 sc->ani.shortcal_timer = timestamp;
462 sc->ani.checkani_timer = timestamp;
463
464 mod_timer(&sc->ani.timer,
465 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
466}
467
Sujithff37e332008-11-24 12:07:55 +0530468/*
469 * Update tx/rx chainmask. For legacy association,
470 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530471 * the chainmask configuration, for bt coexistence, use
472 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530473 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200474void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530475{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700476 struct ath_hw *ah = sc->sc_ah;
477
Sujith3d832612009-08-21 12:00:28 +0530478 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700479 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Sujith2660b812009-02-09 13:27:26 +0530480 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
481 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530482 } else {
Sujith17d79042009-02-09 13:27:03 +0530483 sc->tx_chainmask = 1;
484 sc->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530485 }
486
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700487 DPRINTF(ah, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
Sujith17d79042009-02-09 13:27:03 +0530488 sc->tx_chainmask, sc->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530489}
490
491static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
492{
493 struct ath_node *an;
494
495 an = (struct ath_node *)sta->drv_priv;
496
Sujith87792ef2009-03-30 15:28:48 +0530497 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530498 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530499 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530500 sta->ht_cap.ampdu_factor);
501 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400502 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530503 }
Sujithff37e332008-11-24 12:07:55 +0530504}
505
506static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
507{
508 struct ath_node *an = (struct ath_node *)sta->drv_priv;
509
510 if (sc->sc_flags & SC_OP_TXAGGR)
511 ath_tx_node_cleanup(sc, an);
512}
513
514static void ath9k_tasklet(unsigned long data)
515{
516 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700517 struct ath_hw *ah = sc->sc_ah;
518
Sujith17d79042009-02-09 13:27:03 +0530519 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530520
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400521 ath9k_ps_wakeup(sc);
522
Sujithff37e332008-11-24 12:07:55 +0530523 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530524 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400525 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530526 return;
Sujithff37e332008-11-24 12:07:55 +0530527 }
528
Sujith063d8be2009-03-30 15:28:49 +0530529 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
530 spin_lock_bh(&sc->rx.rxflushlock);
531 ath_rx_tasklet(sc, 0);
532 spin_unlock_bh(&sc->rx.rxflushlock);
533 }
534
535 if (status & ATH9K_INT_TX)
536 ath_tx_tasklet(sc);
537
Gabor Juhos96148322009-07-24 17:27:21 +0200538 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300539 /*
540 * TSF sync does not look correct; remain awake to sync with
541 * the next Beacon.
542 */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700543 DPRINTF(ah, ATH_DBG_PS, "TSFOOR - Sync with next Beacon\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300544 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300545 }
546
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700547 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530548 if (status & ATH9K_INT_GENTIMER)
549 ath_gen_timer_isr(sc->sc_ah);
550
Sujithff37e332008-11-24 12:07:55 +0530551 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700552 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400553 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530554}
555
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100556irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530557{
Sujith063d8be2009-03-30 15:28:49 +0530558#define SCHED_INTR ( \
559 ATH9K_INT_FATAL | \
560 ATH9K_INT_RXORN | \
561 ATH9K_INT_RXEOL | \
562 ATH9K_INT_RX | \
563 ATH9K_INT_TX | \
564 ATH9K_INT_BMISS | \
565 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530566 ATH9K_INT_TSFOOR | \
567 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530568
Sujithff37e332008-11-24 12:07:55 +0530569 struct ath_softc *sc = dev;
Sujithcbe61d8a2009-02-09 13:27:12 +0530570 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530571 enum ath9k_int status;
572 bool sched = false;
573
Sujith063d8be2009-03-30 15:28:49 +0530574 /*
575 * The hardware is not ready/present, don't
576 * touch anything. Note this can happen early
577 * on if the IRQ is shared.
578 */
579 if (sc->sc_flags & SC_OP_INVALID)
580 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530581
Sujithff37e332008-11-24 12:07:55 +0530582
Sujith063d8be2009-03-30 15:28:49 +0530583 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530584
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400585 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530586 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530587
Sujith063d8be2009-03-30 15:28:49 +0530588 /*
589 * Figure out the reason(s) for the interrupt. Note
590 * that the hal returns a pseudo-ISR that may include
591 * bits we haven't explicitly enabled so we mask the
592 * value to insure we only process bits we requested.
593 */
594 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
595 status &= sc->imask; /* discard unasked-for bits */
596
597 /*
598 * If there are no status bits set, then this interrupt was not
599 * for me (should have been caught above).
600 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400601 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530602 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530603
604 /* Cache the status */
605 sc->intrstatus = status;
606
607 if (status & SCHED_INTR)
608 sched = true;
609
610 /*
611 * If a FATAL or RXORN interrupt is received, we have to reset the
612 * chip immediately.
613 */
614 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
615 goto chip_reset;
616
617 if (status & ATH9K_INT_SWBA)
618 tasklet_schedule(&sc->bcon_tasklet);
619
620 if (status & ATH9K_INT_TXURN)
621 ath9k_hw_updatetxtriglevel(ah, true);
622
623 if (status & ATH9K_INT_MIB) {
624 /*
625 * Disable interrupts until we service the MIB
626 * interrupt; otherwise it will continue to
627 * fire.
628 */
629 ath9k_hw_set_interrupts(ah, 0);
630 /*
631 * Let the hal handle the event. We assume
632 * it will clear whatever condition caused
633 * the interrupt.
634 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530635 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530636 ath9k_hw_set_interrupts(ah, sc->imask);
637 }
638
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400639 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
640 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530641 /* Clear RxAbort bit so that we can
642 * receive frames */
643 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400644 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith063d8be2009-03-30 15:28:49 +0530645 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
646 }
Sujith063d8be2009-03-30 15:28:49 +0530647
648chip_reset:
649
Sujith817e11d2008-12-07 21:42:44 +0530650 ath_debug_stat_interrupt(sc, status);
651
Sujithff37e332008-11-24 12:07:55 +0530652 if (sched) {
653 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530654 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530655 tasklet_schedule(&sc->intr_tq);
656 }
657
658 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530659
660#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530661}
662
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700663static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530664 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530665 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700666{
667 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668
669 switch (chan->band) {
670 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530671 switch(channel_type) {
672 case NL80211_CHAN_NO_HT:
673 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700674 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530675 break;
676 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700677 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530678 break;
679 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700680 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530681 break;
682 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700683 break;
684 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530685 switch(channel_type) {
686 case NL80211_CHAN_NO_HT:
687 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700688 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530689 break;
690 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700691 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530692 break;
693 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700694 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530695 break;
696 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700697 break;
698 default:
699 break;
700 }
701
702 return chanmode;
703}
704
Jouni Malinen6ace2892008-12-17 13:32:17 +0200705static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200706 struct ath9k_keyval *hk, const u8 *addr,
707 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700708{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200709 const u8 *key_rxmic;
710 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700711
Jouni Malinen6ace2892008-12-17 13:32:17 +0200712 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
713 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700714
715 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200716 /*
717 * Group key installation - only two key cache entries are used
718 * regardless of splitmic capability since group key is only
719 * used either for TX or RX.
720 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200721 if (authenticator) {
722 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
723 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
724 } else {
725 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
726 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
727 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200728 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700729 }
Sujith17d79042009-02-09 13:27:03 +0530730 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200731 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700732 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
733 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200734 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700735 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200736
737 /* Separate key cache entries for TX and RX */
738
739 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700740 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200741 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
742 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700743 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530744 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 return 0;
746 }
747
748 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
749 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200750 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200751}
752
753static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
754{
755 int i;
756
Sujith17d79042009-02-09 13:27:03 +0530757 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
758 if (test_bit(i, sc->keymap) ||
759 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200760 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530761 if (sc->splitmic &&
762 (test_bit(i + 32, sc->keymap) ||
763 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200764 continue; /* At least one part of TKIP key allocated */
765
766 /* Found a free slot for a TKIP key */
767 return i;
768 }
769 return -1;
770}
771
772static int ath_reserve_key_cache_slot(struct ath_softc *sc)
773{
774 int i;
775
776 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530777 if (sc->splitmic) {
778 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
779 if (!test_bit(i, sc->keymap) &&
780 (test_bit(i + 32, sc->keymap) ||
781 test_bit(i + 64, sc->keymap) ||
782 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200783 return i;
Sujith17d79042009-02-09 13:27:03 +0530784 if (!test_bit(i + 32, sc->keymap) &&
785 (test_bit(i, sc->keymap) ||
786 test_bit(i + 64, sc->keymap) ||
787 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200788 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530789 if (!test_bit(i + 64, sc->keymap) &&
790 (test_bit(i , sc->keymap) ||
791 test_bit(i + 32, sc->keymap) ||
792 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200793 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530794 if (!test_bit(i + 64 + 32, sc->keymap) &&
795 (test_bit(i, sc->keymap) ||
796 test_bit(i + 32, sc->keymap) ||
797 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200798 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200799 }
800 } else {
Sujith17d79042009-02-09 13:27:03 +0530801 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
802 if (!test_bit(i, sc->keymap) &&
803 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200804 return i;
Sujith17d79042009-02-09 13:27:03 +0530805 if (test_bit(i, sc->keymap) &&
806 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200807 return i + 64;
808 }
809 }
810
811 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530812 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200813 /* Do not allow slots that could be needed for TKIP group keys
814 * to be used. This limitation could be removed if we know that
815 * TKIP will not be used. */
816 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
817 continue;
Sujith17d79042009-02-09 13:27:03 +0530818 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200819 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
820 continue;
821 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
822 continue;
823 }
824
Sujith17d79042009-02-09 13:27:03 +0530825 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200826 return i; /* Found a free slot for a key */
827 }
828
829 /* No free slot found */
830 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700831}
832
833static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200834 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100835 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700836 struct ieee80211_key_conf *key)
837{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700838 struct ath9k_keyval hk;
839 const u8 *mac = NULL;
840 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200841 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700842
843 memset(&hk, 0, sizeof(hk));
844
845 switch (key->alg) {
846 case ALG_WEP:
847 hk.kv_type = ATH9K_CIPHER_WEP;
848 break;
849 case ALG_TKIP:
850 hk.kv_type = ATH9K_CIPHER_TKIP;
851 break;
852 case ALG_CCMP:
853 hk.kv_type = ATH9K_CIPHER_AES_CCM;
854 break;
855 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200856 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700857 }
858
Jouni Malinen6ace2892008-12-17 13:32:17 +0200859 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700860 memcpy(hk.kv_val, key->key, key->keylen);
861
Jouni Malinen6ace2892008-12-17 13:32:17 +0200862 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
863 /* For now, use the default keys for broadcast keys. This may
864 * need to change with virtual interfaces. */
865 idx = key->keyidx;
866 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100867 if (WARN_ON(!sta))
868 return -EOPNOTSUPP;
869 mac = sta->addr;
870
Jouni Malinen6ace2892008-12-17 13:32:17 +0200871 if (vif->type != NL80211_IFTYPE_AP) {
872 /* Only keyidx 0 should be used with unicast key, but
873 * allow this for client mode for now. */
874 idx = key->keyidx;
875 } else
876 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700877 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100878 if (WARN_ON(!sta))
879 return -EOPNOTSUPP;
880 mac = sta->addr;
881
Jouni Malinen6ace2892008-12-17 13:32:17 +0200882 if (key->alg == ALG_TKIP)
883 idx = ath_reserve_key_cache_slot_tkip(sc);
884 else
885 idx = ath_reserve_key_cache_slot(sc);
886 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200887 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700888 }
889
890 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200891 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
892 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700893 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200894 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700895
896 if (!ret)
897 return -EIO;
898
Sujith17d79042009-02-09 13:27:03 +0530899 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200900 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530901 set_bit(idx + 64, sc->keymap);
902 if (sc->splitmic) {
903 set_bit(idx + 32, sc->keymap);
904 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200905 }
906 }
907
908 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700909}
910
911static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
912{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200913 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
914 if (key->hw_key_idx < IEEE80211_WEP_NKID)
915 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700916
Sujith17d79042009-02-09 13:27:03 +0530917 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200918 if (key->alg != ALG_TKIP)
919 return;
920
Sujith17d79042009-02-09 13:27:03 +0530921 clear_bit(key->hw_key_idx + 64, sc->keymap);
922 if (sc->splitmic) {
923 clear_bit(key->hw_key_idx + 32, sc->keymap);
924 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200925 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700926}
927
Sujitheb2599c2009-01-23 11:20:44 +0530928static void setup_ht_cap(struct ath_softc *sc,
929 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700930{
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530931 u8 tx_streams, rx_streams;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700932
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200933 ht_info->ht_supported = true;
934 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
935 IEEE80211_HT_CAP_SM_PS |
936 IEEE80211_HT_CAP_SGI_40 |
937 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700938
Sujith9e98ac62009-07-23 15:32:34 +0530939 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
940 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530941
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200942 /* set up supported mcs set */
943 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530944 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
945 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
Sujitheb2599c2009-01-23 11:20:44 +0530946
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530947 if (tx_streams != rx_streams) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700948 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530949 tx_streams, rx_streams);
950 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
951 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
952 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
Sujitheb2599c2009-01-23 11:20:44 +0530953 }
954
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530955 ht_info->mcs.rx_mask[0] = 0xff;
956 if (rx_streams >= 2)
957 ht_info->mcs.rx_mask[1] = 0xff;
958
959 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700960}
961
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530962static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530963 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530964 struct ieee80211_bss_conf *bss_conf)
965{
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530966
967 if (bss_conf->assoc) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700968 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
Sujith17d79042009-02-09 13:27:03 +0530969 bss_conf->aid, sc->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530970
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530971 /* New association, store aid */
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530972 sc->curaid = bss_conf->aid;
973 ath9k_hw_write_associd(sc);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300974
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530975 /*
976 * Request a re-configuration of Beacon related timers
977 * on the receipt of the first Beacon frame (i.e.,
978 * after time sync with the AP).
979 */
980 sc->sc_flags |= SC_OP_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530981
982 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200983 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530984
985 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530986 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530987
Sujith415f7382009-04-13 21:56:46 +0530988 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530989 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700990 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Sujith17d79042009-02-09 13:27:03 +0530991 sc->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +0530992 /* Stop ANI */
993 del_timer_sync(&sc->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530994 }
995}
996
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530997/********************************/
998/* LED functions */
999/********************************/
1000
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301001static void ath_led_blink_work(struct work_struct *work)
1002{
1003 struct ath_softc *sc = container_of(work, struct ath_softc,
1004 ath_led_blink_work.work);
1005
1006 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
1007 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301008
1009 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
1010 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301011 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301012 else
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301013 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301014 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301015
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001016 ieee80211_queue_delayed_work(sc->hw,
1017 &sc->ath_led_blink_work,
1018 (sc->sc_flags & SC_OP_LED_ON) ?
1019 msecs_to_jiffies(sc->led_off_duration) :
1020 msecs_to_jiffies(sc->led_on_duration));
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301021
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +05301022 sc->led_on_duration = sc->led_on_cnt ?
1023 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
1024 ATH_LED_ON_DURATION_IDLE;
1025 sc->led_off_duration = sc->led_off_cnt ?
1026 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
1027 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301028 sc->led_on_cnt = sc->led_off_cnt = 0;
1029 if (sc->sc_flags & SC_OP_LED_ON)
1030 sc->sc_flags &= ~SC_OP_LED_ON;
1031 else
1032 sc->sc_flags |= SC_OP_LED_ON;
1033}
1034
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301035static void ath_led_brightness(struct led_classdev *led_cdev,
1036 enum led_brightness brightness)
1037{
1038 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1039 struct ath_softc *sc = led->sc;
1040
1041 switch (brightness) {
1042 case LED_OFF:
1043 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301044 led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301045 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301046 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301047 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301048 if (led->led_type == ATH_LED_RADIO)
1049 sc->sc_flags &= ~SC_OP_LED_ON;
1050 } else {
1051 sc->led_off_cnt++;
1052 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301053 break;
1054 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301055 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301056 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001057 ieee80211_queue_delayed_work(sc->hw,
1058 &sc->ath_led_blink_work, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301059 } else if (led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301060 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301061 sc->sc_flags |= SC_OP_LED_ON;
1062 } else {
1063 sc->led_on_cnt++;
1064 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301065 break;
1066 default:
1067 break;
1068 }
1069}
1070
1071static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1072 char *trigger)
1073{
1074 int ret;
1075
1076 led->sc = sc;
1077 led->led_cdev.name = led->name;
1078 led->led_cdev.default_trigger = trigger;
1079 led->led_cdev.brightness_set = ath_led_brightness;
1080
1081 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1082 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001083 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301084 "Failed to register led:%s", led->name);
1085 else
1086 led->registered = 1;
1087 return ret;
1088}
1089
1090static void ath_unregister_led(struct ath_led *led)
1091{
1092 if (led->registered) {
1093 led_classdev_unregister(&led->led_cdev);
1094 led->registered = 0;
1095 }
1096}
1097
1098static void ath_deinit_leds(struct ath_softc *sc)
1099{
1100 ath_unregister_led(&sc->assoc_led);
1101 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1102 ath_unregister_led(&sc->tx_led);
1103 ath_unregister_led(&sc->rx_led);
1104 ath_unregister_led(&sc->radio_led);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301105 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301106}
1107
1108static void ath_init_leds(struct ath_softc *sc)
1109{
1110 char *trigger;
1111 int ret;
1112
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301113 if (AR_SREV_9287(sc->sc_ah))
1114 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1115 else
1116 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1117
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301118 /* Configure gpio 1 for output */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301119 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301120 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1121 /* LED off, active low */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301122 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301123
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301124 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1125
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301126 trigger = ieee80211_get_radio_led_name(sc->hw);
1127 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001128 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301129 ret = ath_register_led(sc, &sc->radio_led, trigger);
1130 sc->radio_led.led_type = ATH_LED_RADIO;
1131 if (ret)
1132 goto fail;
1133
1134 trigger = ieee80211_get_assoc_led_name(sc->hw);
1135 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001136 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301137 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1138 sc->assoc_led.led_type = ATH_LED_ASSOC;
1139 if (ret)
1140 goto fail;
1141
1142 trigger = ieee80211_get_tx_led_name(sc->hw);
1143 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001144 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301145 ret = ath_register_led(sc, &sc->tx_led, trigger);
1146 sc->tx_led.led_type = ATH_LED_TX;
1147 if (ret)
1148 goto fail;
1149
1150 trigger = ieee80211_get_rx_led_name(sc->hw);
1151 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001152 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301153 ret = ath_register_led(sc, &sc->rx_led, trigger);
1154 sc->rx_led.led_type = ATH_LED_RX;
1155 if (ret)
1156 goto fail;
1157
1158 return;
1159
1160fail:
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001161 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301162 ath_deinit_leds(sc);
1163}
1164
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001165void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301166{
Sujithcbe61d8a2009-02-09 13:27:12 +05301167 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001168 struct ieee80211_channel *channel = sc->hw->conf.channel;
1169 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301170
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301171 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301172 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +05301173
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301174 if (!ah->curchan)
1175 ah->curchan = ath_get_curchannel(sc, sc->hw);
1176
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301177 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301178 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001179 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001180 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001181 "Unable to reset channel %u (%uMhz) ",
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301182 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001183 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301184 }
1185 spin_unlock_bh(&sc->sc_resetlock);
1186
1187 ath_update_txpow(sc);
1188 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001189 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301190 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301191 return;
1192 }
1193
1194 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001195 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301196
1197 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301198 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301199
1200 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301201 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301202 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301203 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301204
1205 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301206 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301207}
1208
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001209void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301210{
Sujithcbe61d8a2009-02-09 13:27:12 +05301211 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001212 struct ieee80211_channel *channel = sc->hw->conf.channel;
1213 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301214
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301215 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301216 ieee80211_stop_queues(sc->hw);
1217
1218 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301219 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1220 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301221
1222 /* Disable interrupts */
1223 ath9k_hw_set_interrupts(ah, 0);
1224
Sujith043a0402009-01-16 21:38:47 +05301225 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301226 ath_stoprecv(sc); /* turn off frame recv */
1227 ath_flushrecv(sc); /* flush recv queue */
1228
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301229 if (!ah->curchan)
1230 ah->curchan = ath_get_curchannel(sc, sc->hw);
1231
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301232 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301233 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001234 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001235 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301236 "Unable to reset channel %u (%uMhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301237 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001238 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301239 }
1240 spin_unlock_bh(&sc->sc_resetlock);
1241
1242 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301243 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301244 ath9k_ps_restore(sc);
Gabor Juhos38ab4222009-06-17 20:53:21 +02001245 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301246}
1247
Gabor Juhos5077fd32009-03-06 11:17:55 +01001248/*******************/
1249/* Rfkill */
1250/*******************/
1251
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301252static bool ath_is_rfkill_set(struct ath_softc *sc)
1253{
Sujithcbe61d8a2009-02-09 13:27:12 +05301254 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301255
Sujith2660b812009-02-09 13:27:26 +05301256 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1257 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301258}
1259
Johannes Berg3b319aa2009-06-13 14:50:26 +05301260static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301261{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301262 struct ath_wiphy *aphy = hw->priv;
1263 struct ath_softc *sc = aphy->sc;
1264 bool blocked = !!ath_is_rfkill_set(sc);
1265
1266 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
Johannes Berg19d337d2009-06-02 13:01:37 +02001267}
1268
Johannes Berg3b319aa2009-06-13 14:50:26 +05301269static void ath_start_rfkill_poll(struct ath_softc *sc)
Johannes Berg19d337d2009-06-02 13:01:37 +02001270{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301271 struct ath_hw *ah = sc->sc_ah;
Johannes Berg19d337d2009-06-02 13:01:37 +02001272
Johannes Berg3b319aa2009-06-13 14:50:26 +05301273 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1274 wiphy_rfkill_start_polling(sc->hw->wiphy);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301275}
1276
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001277void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001278{
1279 ath_detach(sc);
1280 free_irq(sc->irq, sc);
1281 ath_bus_cleanup(sc);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001282 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001283 ieee80211_free_hw(sc->hw);
1284}
1285
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001286void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301287{
1288 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001289 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05301290 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301291
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301292 ath9k_ps_wakeup(sc);
1293
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001294 dev_dbg(sc->dev, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301295
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001296 ath_deinit_leds(sc);
Sujithe31f7b92009-09-23 13:49:12 +05301297 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001298
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001299 for (i = 0; i < sc->num_sec_wiphy; i++) {
1300 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1301 if (aphy == NULL)
1302 continue;
1303 sc->sec_wiphy[i] = NULL;
1304 ieee80211_unregister_hw(aphy->hw);
1305 ieee80211_free_hw(aphy->hw);
1306 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301307 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301308 ath_rx_cleanup(sc);
1309 ath_tx_cleanup(sc);
1310
Sujith9c84b792008-10-29 10:17:13 +05301311 tasklet_kill(&sc->intr_tq);
1312 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301313
Sujith9c84b792008-10-29 10:17:13 +05301314 if (!(sc->sc_flags & SC_OP_INVALID))
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001315 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301316
Sujith9c84b792008-10-29 10:17:13 +05301317 /* cleanup tx queues */
1318 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1319 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301320 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301321
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001322 if ((sc->btcoex.no_stomp_timer) &&
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001323 ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001324 ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301325
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001326 ath9k_hw_detach(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001327 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001328 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301329}
1330
Bob Copelande3bb2492009-03-30 22:30:30 -04001331static int ath9k_reg_notifier(struct wiphy *wiphy,
1332 struct regulatory_request *request)
1333{
1334 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1335 struct ath_wiphy *aphy = hw->priv;
1336 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001337 struct ath_regulatory *reg = &sc->common.regulatory;
Bob Copelande3bb2492009-03-30 22:30:30 -04001338
1339 return ath_reg_notifier_apply(wiphy, request, reg);
1340}
1341
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001342/*
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001343 * Detects if there is any priority bt traffic
1344 */
1345static void ath_detect_bt_priority(struct ath_softc *sc)
1346{
1347 struct ath_btcoex *btcoex = &sc->btcoex;
1348 struct ath_hw *ah = sc->sc_ah;
1349
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001350 if (ath9k_hw_gpio_get(sc->sc_ah, ah->btcoex_hw.btpriority_gpio))
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001351 btcoex->bt_priority_cnt++;
1352
1353 if (time_after(jiffies, btcoex->bt_priority_time +
1354 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
1355 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
1356 DPRINTF(sc->sc_ah, ATH_DBG_BTCOEX,
1357 "BT priority traffic detected");
1358 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED;
1359 } else {
1360 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
1361 }
1362
1363 btcoex->bt_priority_cnt = 0;
1364 btcoex->bt_priority_time = jiffies;
1365 }
1366}
1367
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001368/*
1369 * Configures appropriate weight based on stomp type.
1370 */
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001371static void ath9k_btcoex_bt_stomp(struct ath_softc *sc,
1372 enum ath_stomp_type stomp_type)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001373{
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001374 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001375
1376 switch (stomp_type) {
1377 case ATH_BTCOEX_STOMP_ALL:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001378 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1379 AR_STOMP_ALL_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001380 break;
1381 case ATH_BTCOEX_STOMP_LOW:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001382 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1383 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001384 break;
1385 case ATH_BTCOEX_STOMP_NONE:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001386 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1387 AR_STOMP_NONE_WLAN_WGHT);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001388 break;
1389 default:
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001390 DPRINTF(ah, ATH_DBG_BTCOEX, "Invalid Stomptype\n");
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001391 break;
1392 }
1393
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001394 ath9k_hw_btcoex_enable(ah);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001395}
1396
1397/*
1398 * This is the master bt coex timer which runs for every
1399 * 45ms, bt traffic will be given priority during 55% of this
1400 * period while wlan gets remaining 45%
1401 */
1402static void ath_btcoex_period_timer(unsigned long data)
1403{
1404 struct ath_softc *sc = (struct ath_softc *) data;
1405 struct ath_hw *ah = sc->sc_ah;
1406 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001407
1408 ath_detect_bt_priority(sc);
1409
1410 spin_lock_bh(&btcoex->btcoex_lock);
1411
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001412 ath9k_btcoex_bt_stomp(sc, btcoex->bt_stomp_type);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001413
1414 spin_unlock_bh(&btcoex->btcoex_lock);
1415
1416 if (btcoex->btcoex_period != btcoex->btcoex_no_stomp) {
1417 if (btcoex->hw_timer_enabled)
1418 ath_gen_timer_stop(ah, btcoex->no_stomp_timer);
1419
1420 ath_gen_timer_start(ah,
1421 btcoex->no_stomp_timer,
1422 (ath9k_hw_gettsf32(ah) +
1423 btcoex->btcoex_no_stomp),
1424 btcoex->btcoex_no_stomp * 10);
1425 btcoex->hw_timer_enabled = true;
1426 }
1427
1428 mod_timer(&btcoex->period_timer, jiffies +
1429 msecs_to_jiffies(ATH_BTCOEX_DEF_BT_PERIOD));
1430}
1431
1432/*
1433 * Generic tsf based hw timer which configures weight
1434 * registers to time slice between wlan and bt traffic
1435 */
1436static void ath_btcoex_no_stomp_timer(void *arg)
1437{
1438 struct ath_softc *sc = (struct ath_softc *)arg;
1439 struct ath_hw *ah = sc->sc_ah;
1440 struct ath_btcoex *btcoex = &sc->btcoex;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001441
1442 DPRINTF(ah, ATH_DBG_BTCOEX, "no stomp timer running \n");
1443
1444 spin_lock_bh(&btcoex->btcoex_lock);
1445
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001446 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001447 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_NONE);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001448 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
Luis R. Rodriguez269ad812009-09-09 15:05:00 -07001449 ath9k_btcoex_bt_stomp(sc, ATH_BTCOEX_STOMP_LOW);
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001450
1451 spin_unlock_bh(&btcoex->btcoex_lock);
1452}
1453
1454static int ath_init_btcoex_timer(struct ath_softc *sc)
1455{
1456 struct ath_btcoex *btcoex = &sc->btcoex;
1457
1458 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000;
1459 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) *
1460 btcoex->btcoex_period / 100;
1461
1462 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
1463 (unsigned long) sc);
1464
1465 spin_lock_init(&btcoex->btcoex_lock);
1466
1467 btcoex->no_stomp_timer = ath_gen_timer_alloc(sc->sc_ah,
1468 ath_btcoex_no_stomp_timer,
1469 ath_btcoex_no_stomp_timer,
1470 (void *) sc, AR_FIRST_NDP_TIMER);
1471
1472 if (!btcoex->no_stomp_timer)
1473 return -ENOMEM;
1474
1475 return 0;
1476}
1477
1478/*
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001479 * Initialize and fill ath_softc, ath_sofct is the
1480 * "Software Carrier" struct. Historically it has existed
1481 * to allow the separation between hardware specific
1482 * variables (now in ath_hw) and driver specific variables.
1483 */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301484static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
Sujithff37e332008-11-24 12:07:55 +05301485{
Sujithcbe61d8a2009-02-09 13:27:12 +05301486 struct ath_hw *ah = NULL;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001487 int r = 0, i;
Sujithff37e332008-11-24 12:07:55 +05301488 int csz = 0;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001489 int qnum;
Sujithff37e332008-11-24 12:07:55 +05301490
1491 /* XXX: hardware will not be ready until ath_open() being called */
1492 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301493
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001494 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301495 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001496 spin_lock_init(&sc->sc_serial_rw);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05301497 spin_lock_init(&sc->ani_lock);
Gabor Juhos04717cc2009-07-14 20:17:13 -04001498 spin_lock_init(&sc->sc_pm_lock);
Sujithaa33de02008-12-18 11:40:16 +05301499 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301500 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301501 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301502 (unsigned long)sc);
1503
1504 /*
1505 * Cache line size is used to size and align various
1506 * structures used to communicate with the hardware.
1507 */
Gabor Juhos88d15702009-01-14 20:17:04 +01001508 ath_read_cachesize(sc, &csz);
Sujithff37e332008-11-24 12:07:55 +05301509 /* XXX assert csz is non-zero */
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -07001510 sc->common.cachelsz = csz << 2; /* convert to bytes */
Sujithff37e332008-11-24 12:07:55 +05301511
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001512 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1513 if (!ah) {
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001514 r = -ENOMEM;
1515 goto bad_no_ah;
1516 }
1517
1518 ah->ah_sc = sc;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -07001519 ah->hw_version.devid = devid;
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301520 ah->hw_version.subsysid = subsysid;
Luis R. Rodrigueze1e2f932009-08-03 12:24:38 -07001521 sc->sc_ah = ah;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001522
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001523 if (ath9k_init_debug(ah) < 0)
1524 dev_err(sc->dev, "Unable to create debugfs files\n");
1525
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001526 r = ath9k_hw_init(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001527 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001528 DPRINTF(ah, ATH_DBG_FATAL,
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001529 "Unable to initialize hardware; "
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001530 "initialization status: %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301531 goto bad;
1532 }
Sujithff37e332008-11-24 12:07:55 +05301533
1534 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301535 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301536 if (sc->keymax > ATH_KEYMAX) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001537 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05301538 "Warning, using only %u entries in %u key cache\n",
Sujith17d79042009-02-09 13:27:03 +05301539 ATH_KEYMAX, sc->keymax);
1540 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301541 }
1542
1543 /*
1544 * Reset the key cache since some parts do not
1545 * reset the contents on initial power up.
1546 */
Sujith17d79042009-02-09 13:27:03 +05301547 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301548 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301549
Sujithff37e332008-11-24 12:07:55 +05301550 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301551 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001552
Sujithff37e332008-11-24 12:07:55 +05301553 /* Setup rate tables */
1554
1555 ath_rate_attach(sc);
1556 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1557 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1558
1559 /*
1560 * Allocate hardware transmit queues: one queue for
1561 * beacon frames and one data queue for each QoS
1562 * priority. Note that the hal handles reseting
1563 * these queues at the needed time.
1564 */
Sujithb77f4832008-12-07 21:44:03 +05301565 sc->beacon.beaconq = ath_beaconq_setup(ah);
1566 if (sc->beacon.beaconq == -1) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001567 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301568 "Unable to setup a beacon xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001569 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301570 goto bad2;
1571 }
Sujithb77f4832008-12-07 21:44:03 +05301572 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1573 if (sc->beacon.cabq == NULL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001574 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301575 "Unable to setup CAB xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001576 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301577 goto bad2;
1578 }
1579
Sujith17d79042009-02-09 13:27:03 +05301580 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301581 ath_cabq_update(sc);
1582
Sujithb77f4832008-12-07 21:44:03 +05301583 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1584 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301585
1586 /* Setup data queues */
1587 /* NB: ensure BK queue is the lowest priority h/w queue */
1588 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001589 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301590 "Unable to setup xmit queue for BK traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001591 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301592 goto bad2;
1593 }
1594
1595 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001596 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301597 "Unable to setup xmit queue for BE traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001598 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301599 goto bad2;
1600 }
1601 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001602 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301603 "Unable to setup xmit queue for VI traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001604 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301605 goto bad2;
1606 }
1607 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001608 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301609 "Unable to setup xmit queue for VO traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001610 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301611 goto bad2;
1612 }
1613
1614 /* Initializes the noise floor to a reasonable default value.
1615 * Later on this will be updated during ANI processing. */
1616
Sujith17d79042009-02-09 13:27:03 +05301617 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1618 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301619
1620 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1621 ATH9K_CIPHER_TKIP, NULL)) {
1622 /*
1623 * Whether we should enable h/w TKIP MIC.
1624 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1625 * report WMM capable, so it's always safe to turn on
1626 * TKIP MIC in this case.
1627 */
1628 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1629 0, 1, NULL);
1630 }
1631
1632 /*
1633 * Check whether the separate key cache entries
1634 * are required to handle both tx+rx MIC keys.
1635 * With split mic keys the number of stations is limited
1636 * to 27 otherwise 59.
1637 */
1638 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1639 ATH9K_CIPHER_TKIP, NULL)
1640 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1641 ATH9K_CIPHER_MIC, NULL)
1642 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1643 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301644 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301645
1646 /* turn on mcast key search if possible */
1647 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1648 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1649 1, NULL);
1650
Sujith17d79042009-02-09 13:27:03 +05301651 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301652
1653 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301654 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301655 sc->sc_flags |= SC_OP_TXAGGR;
1656 sc->sc_flags |= SC_OP_RXAGGR;
1657 }
1658
Sujith2660b812009-02-09 13:27:26 +05301659 sc->tx_chainmask = ah->caps.tx_chainmask;
1660 sc->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301661
1662 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301663 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301664
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001665 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Sujithba52da52009-02-09 13:27:10 +05301666 memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301667
Sujithb77f4832008-12-07 21:44:03 +05301668 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301669
1670 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001671 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001672 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001673 sc->beacon.bslot_aphy[i] = NULL;
1674 }
Sujithff37e332008-11-24 12:07:55 +05301675
Sujithff37e332008-11-24 12:07:55 +05301676 /* setup channels and rates */
1677
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001678 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301679 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1680 sc->rates[IEEE80211_BAND_2GHZ];
1681 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001682 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1683 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301684
Sujith2660b812009-02-09 13:27:26 +05301685 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001686 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301687 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1688 sc->rates[IEEE80211_BAND_5GHZ];
1689 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001690 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1691 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301692 }
1693
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001694 switch (ah->btcoex_hw.scheme) {
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001695 case ATH_BTCOEX_CFG_NONE:
1696 break;
1697 case ATH_BTCOEX_CFG_2WIRE:
1698 ath9k_hw_btcoex_init_2wire(ah);
1699 break;
1700 case ATH_BTCOEX_CFG_3WIRE:
1701 ath9k_hw_btcoex_init_3wire(ah);
1702 r = ath_init_btcoex_timer(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301703 if (r)
1704 goto bad2;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001705 qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001706 ath9k_hw_init_btcoex_hw(ah, qnum);
Luis R. Rodrigueze08a6ac2009-09-09 14:26:15 -07001707 sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001708 break;
1709 default:
1710 WARN_ON(1);
1711 break;
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301712 }
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301713
Sujithff37e332008-11-24 12:07:55 +05301714 return 0;
1715bad2:
1716 /* cleanup tx queues */
1717 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1718 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301719 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301720bad:
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001721 ath9k_hw_detach(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001722bad_no_ah:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001723 ath9k_exit_debug(sc->sc_ah);
1724 sc->sc_ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301725
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001726 return r;
Sujithff37e332008-11-24 12:07:55 +05301727}
1728
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001729void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301730{
Sujith9c84b792008-10-29 10:17:13 +05301731 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1732 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1733 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301734 IEEE80211_HW_AMPDU_AGGREGATION |
1735 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301736 IEEE80211_HW_PS_NULLFUNC_STACK |
1737 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301738
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001739 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001740 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1741
Sujith9c84b792008-10-29 10:17:13 +05301742 hw->wiphy->interface_modes =
1743 BIT(NL80211_IFTYPE_AP) |
1744 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001745 BIT(NL80211_IFTYPE_ADHOC) |
1746 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301747
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301748 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301749 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301750 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001751 hw->max_listen_interval = 10;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001752 /* Hardware supports 10 but we use 4 */
1753 hw->max_rate_tries = 4;
Sujith528f0c62008-10-29 10:14:26 +05301754 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301755 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301756
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301757 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301758
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001759 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1760 &sc->sbands[IEEE80211_BAND_2GHZ];
1761 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1762 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1763 &sc->sbands[IEEE80211_BAND_5GHZ];
1764}
1765
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001766/* Device driver core initialization */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301767int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001768{
1769 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001770 struct ath_hw *ah;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001771 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001772 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001773
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001774 dev_dbg(sc->dev, "Attach ATH hw\n");
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001775
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301776 error = ath_init_softc(devid, sc, subsysid);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001777 if (error != 0)
1778 return error;
1779
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001780 ah = sc->sc_ah;
1781
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001782 /* get mac address from hardware and set in mac80211 */
1783
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001784 SET_IEEE80211_PERM_ADDR(hw, ah->macaddr);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001785
1786 ath_set_hw_capab(sc, hw);
1787
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001788 error = ath_regd_init(&sc->common.regulatory, sc->hw->wiphy,
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001789 ath9k_reg_notifier);
1790 if (error)
1791 return error;
1792
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001793 reg = &sc->common.regulatory;
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001794
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001795 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301796 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001797 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301798 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301799 }
1800
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301801 /* initialize tx/rx engine */
1802 error = ath_tx_init(sc, ATH_TXBUF);
1803 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301804 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301805
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301806 error = ath_rx_init(sc, ATH_RXBUF);
1807 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301808 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301809
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001810 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001811 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1812 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001813
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301814 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301815
Bob Copeland3a702e42009-03-30 22:30:29 -04001816 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001817 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001818 if (error)
1819 goto error_attach;
1820 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001821
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301822 /* Initialize LED control */
1823 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301824
Johannes Berg3b319aa2009-06-13 14:50:26 +05301825 ath_start_rfkill_poll(sc);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001826
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301827 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301828
1829error_attach:
1830 /* cleanup tx queues */
1831 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1832 if (ATH_TXQ_SETUP(sc, i))
1833 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1834
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001835 ath9k_hw_detach(ah);
1836 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001837 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301838
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301839 return error;
1840}
1841
Sujithff37e332008-11-24 12:07:55 +05301842int ath_reset(struct ath_softc *sc, bool retry_tx)
1843{
Sujithcbe61d8a2009-02-09 13:27:12 +05301844 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001845 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001846 int r;
Sujithff37e332008-11-24 12:07:55 +05301847
1848 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301849 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301850 ath_stoprecv(sc);
1851 ath_flushrecv(sc);
1852
1853 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301854 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001855 if (r)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001856 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301857 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301858 spin_unlock_bh(&sc->sc_resetlock);
1859
1860 if (ath_startrecv(sc) != 0)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001861 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301862
1863 /*
1864 * We may be doing a reset in response to a request
1865 * that changes the channel so update any state that
1866 * might change as a result.
1867 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001868 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301869
1870 ath_update_txpow(sc);
1871
1872 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001873 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301874
Sujith17d79042009-02-09 13:27:03 +05301875 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301876
1877 if (retry_tx) {
1878 int i;
1879 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1880 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301881 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1882 ath_txq_schedule(sc, &sc->tx.txq[i]);
1883 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301884 }
1885 }
1886 }
1887
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001888 return r;
Sujithff37e332008-11-24 12:07:55 +05301889}
1890
1891/*
1892 * This function will allocate both the DMA descriptor structure, and the
1893 * buffers it contains. These are used to contain the descriptors used
1894 * by the system.
1895*/
1896int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1897 struct list_head *head, const char *name,
1898 int nbuf, int ndesc)
1899{
1900#define DS2PHYS(_dd, _ds) \
1901 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1902#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1903#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1904
1905 struct ath_desc *ds;
1906 struct ath_buf *bf;
1907 int i, bsize, error;
1908
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001909 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Sujith04bd4632008-11-28 22:18:05 +05301910 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05301911
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05301912 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05301913 /* ath_desc must be a multiple of DWORDs */
1914 if ((sizeof(struct ath_desc) % 4) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001915 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
Sujithff37e332008-11-24 12:07:55 +05301916 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1917 error = -ENOMEM;
1918 goto fail;
1919 }
1920
Sujithff37e332008-11-24 12:07:55 +05301921 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1922
1923 /*
1924 * Need additional DMA memory because we can't use
1925 * descriptors that cross the 4K page boundary. Assume
1926 * one skipped descriptor per 4K page.
1927 */
Sujith2660b812009-02-09 13:27:26 +05301928 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05301929 u32 ndesc_skipped =
1930 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1931 u32 dma_len;
1932
1933 while (ndesc_skipped) {
1934 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1935 dd->dd_desc_len += dma_len;
1936
1937 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
1938 };
1939 }
1940
1941 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001942 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301943 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301944 if (dd->dd_desc == NULL) {
1945 error = -ENOMEM;
1946 goto fail;
1947 }
1948 ds = dd->dd_desc;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001949 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Sujithae459af2009-03-30 15:28:40 +05301950 name, ds, (u32) dd->dd_desc_len,
Sujithff37e332008-11-24 12:07:55 +05301951 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1952
1953 /* allocate buffers */
1954 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301955 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301956 if (bf == NULL) {
1957 error = -ENOMEM;
1958 goto fail2;
1959 }
Sujithff37e332008-11-24 12:07:55 +05301960 dd->dd_bufptr = bf;
1961
Sujithff37e332008-11-24 12:07:55 +05301962 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
1963 bf->bf_desc = ds;
1964 bf->bf_daddr = DS2PHYS(dd, ds);
1965
Sujith2660b812009-02-09 13:27:26 +05301966 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05301967 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1968 /*
1969 * Skip descriptor addresses which can cause 4KB
1970 * boundary crossing (addr + length) with a 32 dword
1971 * descriptor fetch.
1972 */
1973 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
1974 ASSERT((caddr_t) bf->bf_desc <
1975 ((caddr_t) dd->dd_desc +
1976 dd->dd_desc_len));
1977
1978 ds += ndesc;
1979 bf->bf_desc = ds;
1980 bf->bf_daddr = DS2PHYS(dd, ds);
1981 }
1982 }
1983 list_add_tail(&bf->list, head);
1984 }
1985 return 0;
1986fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01001987 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1988 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05301989fail:
1990 memset(dd, 0, sizeof(*dd));
1991 return error;
1992#undef ATH_DESC_4KB_BOUND_CHECK
1993#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1994#undef DS2PHYS
1995}
1996
1997void ath_descdma_cleanup(struct ath_softc *sc,
1998 struct ath_descdma *dd,
1999 struct list_head *head)
2000{
Gabor Juhos7da3c552009-01-14 20:17:03 +01002001 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
2002 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05302003
2004 INIT_LIST_HEAD(head);
2005 kfree(dd->dd_bufptr);
2006 memset(dd, 0, sizeof(*dd));
2007}
2008
2009int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
2010{
2011 int qnum;
2012
2013 switch (queue) {
2014 case 0:
Sujithb77f4832008-12-07 21:44:03 +05302015 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05302016 break;
2017 case 1:
Sujithb77f4832008-12-07 21:44:03 +05302018 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05302019 break;
2020 case 2:
Sujithb77f4832008-12-07 21:44:03 +05302021 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302022 break;
2023 case 3:
Sujithb77f4832008-12-07 21:44:03 +05302024 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05302025 break;
2026 default:
Sujithb77f4832008-12-07 21:44:03 +05302027 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05302028 break;
2029 }
2030
2031 return qnum;
2032}
2033
2034int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
2035{
2036 int qnum;
2037
2038 switch (queue) {
2039 case ATH9K_WME_AC_VO:
2040 qnum = 0;
2041 break;
2042 case ATH9K_WME_AC_VI:
2043 qnum = 1;
2044 break;
2045 case ATH9K_WME_AC_BE:
2046 qnum = 2;
2047 break;
2048 case ATH9K_WME_AC_BK:
2049 qnum = 3;
2050 break;
2051 default:
2052 qnum = -1;
2053 break;
2054 }
2055
2056 return qnum;
2057}
2058
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002059/* XXX: Remove me once we don't depend on ath9k_channel for all
2060 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002061void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
2062 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002063{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002064 struct ieee80211_channel *chan = hw->conf.channel;
2065 struct ieee80211_conf *conf = &hw->conf;
2066
2067 ichan->channel = chan->center_freq;
2068 ichan->chan = chan;
2069
2070 if (chan->band == IEEE80211_BAND_2GHZ) {
2071 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05302072 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002073 } else {
2074 ichan->chanmode = CHANNEL_A;
2075 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
2076 }
2077
2078 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
2079
2080 if (conf_is_ht(conf)) {
2081 if (conf_is_ht40(conf))
2082 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
2083
2084 ichan->chanmode = ath_get_extchanmode(sc, chan,
2085 conf->channel_type);
2086 }
2087}
2088
Sujithff37e332008-11-24 12:07:55 +05302089/**********************/
2090/* mac80211 callbacks */
2091/**********************/
2092
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002093/*
2094 * (Re)start btcoex timers
2095 */
2096static void ath9k_btcoex_timer_resume(struct ath_softc *sc)
2097{
2098 struct ath_btcoex *btcoex = &sc->btcoex;
2099 struct ath_hw *ah = sc->sc_ah;
2100
2101 DPRINTF(ah, ATH_DBG_BTCOEX, "Starting btcoex timers");
2102
2103 /* make sure duty cycle timer is also stopped when resuming */
2104 if (btcoex->hw_timer_enabled)
2105 ath_gen_timer_stop(sc->sc_ah, btcoex->no_stomp_timer);
2106
2107 btcoex->bt_priority_cnt = 0;
2108 btcoex->bt_priority_time = jiffies;
2109 sc->sc_flags &= ~SC_OP_BT_PRIORITY_DETECTED;
2110
2111 mod_timer(&btcoex->period_timer, jiffies);
2112}
2113
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002114static int ath9k_start(struct ieee80211_hw *hw)
2115{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002116 struct ath_wiphy *aphy = hw->priv;
2117 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002118 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002119 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05302120 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302121 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002122
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002123 DPRINTF(ah, ATH_DBG_CONFIG, "Starting driver with "
Sujith04bd4632008-11-28 22:18:05 +05302124 "initial channel: %d MHz\n", curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002125
Sujith141b38b2009-02-04 08:10:07 +05302126 mutex_lock(&sc->mutex);
2127
Jouni Malinen9580a222009-03-03 19:23:33 +02002128 if (ath9k_wiphy_started(sc)) {
2129 if (sc->chan_idx == curchan->hw_value) {
2130 /*
2131 * Already on the operational channel, the new wiphy
2132 * can be marked active.
2133 */
2134 aphy->state = ATH_WIPHY_ACTIVE;
2135 ieee80211_wake_queues(hw);
2136 } else {
2137 /*
2138 * Another wiphy is on another channel, start the new
2139 * wiphy in paused state.
2140 */
2141 aphy->state = ATH_WIPHY_PAUSED;
2142 ieee80211_stop_queues(hw);
2143 }
2144 mutex_unlock(&sc->mutex);
2145 return 0;
2146 }
2147 aphy->state = ATH_WIPHY_ACTIVE;
2148
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002149 /* setup initial channel */
2150
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302151 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002152
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05302153 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002154
Sujithff37e332008-11-24 12:07:55 +05302155 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002156 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05302157
2158 /*
2159 * The basic interface to setting the hardware in a good
2160 * state is ``reset''. On return the hardware is known to
2161 * be powered up and with interrupts disabled. This must
2162 * be followed by initialization of the appropriate bits
2163 * and then setup of the interrupt mask.
2164 */
2165 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002166 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002167 if (r) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002168 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05302169 "Unable to reset hardware; reset status %d "
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002170 "(freq %u MHz)\n", r,
2171 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05302172 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05302173 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002174 }
Sujithff37e332008-11-24 12:07:55 +05302175 spin_unlock_bh(&sc->sc_resetlock);
2176
2177 /*
2178 * This is needed only to setup initial state
2179 * but it's best done after a reset.
2180 */
2181 ath_update_txpow(sc);
2182
2183 /*
2184 * Setup the hardware after reset:
2185 * The receive engine is set going.
2186 * Frame transmit is handled entirely
2187 * in the frame output path; there's nothing to do
2188 * here except setup the interrupt mask.
2189 */
2190 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002191 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05302192 r = -EIO;
2193 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05302194 }
2195
2196 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05302197 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05302198 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2199 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2200
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002201 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05302202 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05302203
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002204 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302205 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302206
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002207 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302208
2209 sc->sc_flags &= ~SC_OP_INVALID;
2210
2211 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302212 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002213 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302214
Jouni Malinenbce048d2009-03-03 19:23:28 +02002215 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002216
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002217 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002218
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002219 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
2220 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07002221 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
2222 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002223 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05302224
Vasanthakumar Thiagarajan7b6840a2009-09-07 17:46:49 +05302225 ath_pcie_aspm_disable(sc);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002226 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002227 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302228 }
2229
Sujith141b38b2009-02-04 08:10:07 +05302230mutex_unlock:
2231 mutex_unlock(&sc->mutex);
2232
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002233 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002234}
2235
2236static int ath9k_tx(struct ieee80211_hw *hw,
2237 struct sk_buff *skb)
2238{
Jouni Malinen147583c2008-08-11 14:01:50 +03002239 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002240 struct ath_wiphy *aphy = hw->priv;
2241 struct ath_softc *sc = aphy->sc;
Sujith528f0c62008-10-29 10:14:26 +05302242 struct ath_tx_control txctl;
2243 int hdrlen, padsize;
2244
Jouni Malinen8089cc42009-03-03 19:23:38 +02002245 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Jouni Malinenee166a02009-03-03 19:23:36 +02002246 printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
2247 "%d\n", wiphy_name(hw->wiphy), aphy->state);
2248 goto exit;
2249 }
2250
Gabor Juhos96148322009-07-24 17:27:21 +02002251 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03002252 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2253 /*
2254 * mac80211 does not set PM field for normal data frames, so we
2255 * need to update that based on the current PS mode.
2256 */
2257 if (ieee80211_is_data(hdr->frame_control) &&
2258 !ieee80211_is_nullfunc(hdr->frame_control) &&
2259 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002260 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Add PM=1 for a TX frame "
Jouni Malinendc8c4582009-05-19 17:01:42 +03002261 "while in PS mode\n");
2262 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2263 }
2264 }
2265
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002266 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2267 /*
2268 * We are using PS-Poll and mac80211 can request TX while in
2269 * power save mode. Need to wake up hardware for the TX to be
2270 * completed and if needed, also for RX of buffered frames.
2271 */
2272 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2273 ath9k_ps_wakeup(sc);
2274 ath9k_hw_setrxabort(sc->sc_ah, 0);
2275 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002276 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Sending PS-Poll to pick a "
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002277 "buffered frame\n");
2278 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2279 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002280 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Wake up to complete TX\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002281 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2282 }
2283 /*
2284 * The actual restore operation will happen only after
2285 * the sc_flags bit is cleared. We are just dropping
2286 * the ps_usecount here.
2287 */
2288 ath9k_ps_restore(sc);
2289 }
2290
Sujith528f0c62008-10-29 10:14:26 +05302291 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002292
2293 /*
2294 * As a temporary workaround, assign seq# here; this will likely need
2295 * to be cleaned up to work better with Beacon transmission and virtual
2296 * BSSes.
2297 */
2298 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2299 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2300 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302301 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002302 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302303 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002304 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305
2306 /* Add the padding after the header if this is not already done */
2307 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2308 if (hdrlen & 3) {
2309 padsize = hdrlen % 4;
2310 if (skb_headroom(skb) < padsize)
2311 return -1;
2312 skb_push(skb, padsize);
2313 memmove(skb->data, skb->data + padsize, hdrlen);
2314 }
2315
Sujith528f0c62008-10-29 10:14:26 +05302316 /* Check if a tx queue is available */
2317
2318 txctl.txq = ath_test_get_txq(sc, skb);
2319 if (!txctl.txq)
2320 goto exit;
2321
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002322 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002323
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002324 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002325 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302326 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002327 }
2328
2329 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302330exit:
2331 dev_kfree_skb_any(skb);
2332 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002333}
2334
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002335/*
2336 * Pause btcoex timer and bt duty cycle timer
2337 */
2338static void ath9k_btcoex_timer_pause(struct ath_softc *sc)
2339{
2340 struct ath_btcoex *btcoex = &sc->btcoex;
2341 struct ath_hw *ah = sc->sc_ah;
2342
2343 del_timer_sync(&btcoex->period_timer);
2344
2345 if (btcoex->hw_timer_enabled)
2346 ath_gen_timer_stop(ah, btcoex->no_stomp_timer);
2347
2348 btcoex->hw_timer_enabled = false;
2349}
2350
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002351static void ath9k_stop(struct ieee80211_hw *hw)
2352{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002353 struct ath_wiphy *aphy = hw->priv;
2354 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002355 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05302356
Sujith4c483812009-08-18 10:51:52 +05302357 mutex_lock(&sc->mutex);
2358
Jouni Malinen9580a222009-03-03 19:23:33 +02002359 aphy->state = ATH_WIPHY_INACTIVE;
2360
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07002361 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2362 cancel_delayed_work_sync(&sc->tx_complete_work);
2363
2364 if (!sc->num_sec_wiphy) {
2365 cancel_delayed_work_sync(&sc->wiphy_work);
2366 cancel_work_sync(&sc->chan_work);
2367 }
2368
Sujith9c84b792008-10-29 10:17:13 +05302369 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002370 DPRINTF(ah, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05302371 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05302372 return;
2373 }
2374
Jouni Malinen9580a222009-03-03 19:23:33 +02002375 if (ath9k_wiphy_started(sc)) {
2376 mutex_unlock(&sc->mutex);
2377 return; /* another wiphy still in use */
2378 }
2379
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002380 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002381 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07002382 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07002383 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302384 }
2385
Sujithff37e332008-11-24 12:07:55 +05302386 /* make sure h/w will not generate any interrupt
2387 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002388 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05302389
2390 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302391 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302392 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002393 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05302394 } else
Sujithb77f4832008-12-07 21:44:03 +05302395 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302396
Sujithff37e332008-11-24 12:07:55 +05302397 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002398 ath9k_hw_disable(ah);
2399 ath9k_hw_configpcipowersave(ah, 1, 1);
2400 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05302401
2402 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403
Sujith141b38b2009-02-04 08:10:07 +05302404 mutex_unlock(&sc->mutex);
2405
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002406 DPRINTF(ah, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002407}
2408
2409static int ath9k_add_interface(struct ieee80211_hw *hw,
2410 struct ieee80211_if_init_conf *conf)
2411{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002412 struct ath_wiphy *aphy = hw->priv;
2413 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302414 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002415 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002416 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002417
Sujith141b38b2009-02-04 08:10:07 +05302418 mutex_lock(&sc->mutex);
2419
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002420 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2421 sc->nvifs > 0) {
2422 ret = -ENOBUFS;
2423 goto out;
2424 }
2425
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002426 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002427 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002428 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002429 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002430 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002431 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002432 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002433 if (sc->nbcnvifs >= ATH_BCBUF) {
2434 ret = -ENOBUFS;
2435 goto out;
2436 }
Pat Erley9cb54122009-03-20 22:59:59 -04002437 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002438 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002439 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002440 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302441 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002442 ret = -EOPNOTSUPP;
2443 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002444 }
2445
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002446 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002447
Sujith17d79042009-02-09 13:27:03 +05302448 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302449 avp->av_opmode = ic_opmode;
2450 avp->av_bslot = -1;
2451
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002452 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002453
2454 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2455 ath9k_set_bssid_mask(hw);
2456
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002457 if (sc->nvifs > 1)
2458 goto out; /* skip global settings for secondary vif */
2459
Sujithb238e902009-03-03 10:16:56 +05302460 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302461 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302462 sc->sc_flags |= SC_OP_TSF_RESET;
2463 }
Sujith5640b082008-10-29 10:16:06 +05302464
Sujith5640b082008-10-29 10:16:06 +05302465 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302466 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302467
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302468 /*
2469 * Enable MIB interrupts when there are hardware phy counters.
2470 * Note we only do this (at the moment) for station mode.
2471 */
Sujith4af9cf42009-02-12 10:06:47 +05302472 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002473 (conf->type == NL80211_IFTYPE_ADHOC) ||
2474 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05302475 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05302476 sc->imask |= ATH9K_INT_TSFOOR;
2477 }
2478
Sujith17d79042009-02-09 13:27:03 +05302479 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302480
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05302481 if (conf->type == NL80211_IFTYPE_AP ||
2482 conf->type == NL80211_IFTYPE_ADHOC ||
2483 conf->type == NL80211_IFTYPE_MONITOR)
Sujith415f7382009-04-13 21:56:46 +05302484 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002485
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002486out:
Sujith141b38b2009-02-04 08:10:07 +05302487 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002488 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002489}
2490
2491static void ath9k_remove_interface(struct ieee80211_hw *hw,
2492 struct ieee80211_if_init_conf *conf)
2493{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002494 struct ath_wiphy *aphy = hw->priv;
2495 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302496 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002497 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002498
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002499 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002500
Sujith141b38b2009-02-04 08:10:07 +05302501 mutex_lock(&sc->mutex);
2502
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002503 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302504 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002506 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002507 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2508 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2509 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302510 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002511 ath_beacon_return(sc, avp);
2512 }
2513
Sujith672840a2008-08-11 14:05:08 +05302514 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002515
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002516 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2517 if (sc->beacon.bslot[i] == conf->vif) {
2518 printk(KERN_DEBUG "%s: vif had allocated beacon "
2519 "slot\n", __func__);
2520 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002521 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002522 }
2523 }
2524
Sujith17d79042009-02-09 13:27:03 +05302525 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302526
2527 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528}
2529
Johannes Berge8975582008-10-09 12:18:51 +02002530static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002531{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002532 struct ath_wiphy *aphy = hw->priv;
2533 struct ath_softc *sc = aphy->sc;
Johannes Berge8975582008-10-09 12:18:51 +02002534 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302535 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002536 bool all_wiphys_idle = false, disable_radio = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002537
Sujithaa33de02008-12-18 11:40:16 +05302538 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302539
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002540 /* Leave this as the first check */
2541 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2542
2543 spin_lock_bh(&sc->wiphy_lock);
2544 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2545 spin_unlock_bh(&sc->wiphy_lock);
2546
2547 if (conf->flags & IEEE80211_CONF_IDLE){
2548 if (all_wiphys_idle)
2549 disable_radio = true;
2550 }
2551 else if (all_wiphys_idle) {
2552 ath_radio_enable(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002553 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002554 "not-idle: enabling radio\n");
2555 }
2556 }
2557
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302558 if (changed & IEEE80211_CONF_CHANGE_PS) {
2559 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302560 if (!(ah->caps.hw_caps &
2561 ATH9K_HW_CAP_AUTOSLEEP)) {
2562 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2563 sc->imask |= ATH9K_INT_TIM_TIMER;
2564 ath9k_hw_set_interrupts(sc->sc_ah,
2565 sc->imask);
2566 }
2567 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302568 }
Gabor Juhos96148322009-07-24 17:27:21 +02002569 sc->ps_enabled = true;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302570 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02002571 sc->ps_enabled = false;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302572 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302573 if (!(ah->caps.hw_caps &
2574 ATH9K_HW_CAP_AUTOSLEEP)) {
2575 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002576 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2577 SC_OP_WAIT_FOR_CAB |
2578 SC_OP_WAIT_FOR_PSPOLL_DATA |
2579 SC_OP_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302580 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2581 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2582 ath9k_hw_set_interrupts(sc->sc_ah,
2583 sc->imask);
2584 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302585 }
2586 }
2587 }
2588
Johannes Berg47979382009-01-07 10:13:27 +01002589 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302590 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002591 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002593 aphy->chan_idx = pos;
2594 aphy->chan_is_ht = conf_is_ht(conf);
2595
Jouni Malinen8089cc42009-03-03 19:23:38 +02002596 if (aphy->state == ATH_WIPHY_SCAN ||
2597 aphy->state == ATH_WIPHY_ACTIVE)
2598 ath9k_wiphy_pause_all_forced(sc, aphy);
2599 else {
2600 /*
2601 * Do not change operational channel based on a paused
2602 * wiphy changes.
2603 */
2604 goto skip_chan_change;
2605 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002606
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002607 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
Sujith04bd4632008-11-28 22:18:05 +05302608 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002609
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002610 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002611 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302612
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002613 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302614
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002615 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002616 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302617 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302618 return -EINVAL;
2619 }
Sujith094d05d2008-12-12 11:57:43 +05302620 }
Sujith86b89ee2008-08-07 10:54:57 +05302621
Jouni Malinen8089cc42009-03-03 19:23:38 +02002622skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002623 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302624 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002625
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002626 if (disable_radio) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002627 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002628 ath_radio_disable(sc);
2629 }
2630
Sujithaa33de02008-12-18 11:40:16 +05302631 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302632
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002633 return 0;
2634}
2635
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002636#define SUPPORTED_FILTERS \
2637 (FIF_PROMISC_IN_BSS | \
2638 FIF_ALLMULTI | \
2639 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04002640 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002641 FIF_OTHER_BSS | \
2642 FIF_BCN_PRBRESP_PROMISC | \
2643 FIF_FCSFAIL)
2644
Sujith7dcfdcd2008-08-11 14:03:13 +05302645/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002646static void ath9k_configure_filter(struct ieee80211_hw *hw,
2647 unsigned int changed_flags,
2648 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002649 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002651 struct ath_wiphy *aphy = hw->priv;
2652 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302653 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002654
2655 changed_flags &= SUPPORTED_FILTERS;
2656 *total_flags &= SUPPORTED_FILTERS;
2657
Sujithb77f4832008-12-07 21:44:03 +05302658 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002659 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302660 rfilt = ath_calcrxfilter(sc);
2661 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002662 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302663
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002664 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002665}
2666
2667static void ath9k_sta_notify(struct ieee80211_hw *hw,
2668 struct ieee80211_vif *vif,
2669 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002670 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002671{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002672 struct ath_wiphy *aphy = hw->priv;
2673 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002674
2675 switch (cmd) {
2676 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302677 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002678 break;
2679 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302680 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002681 break;
2682 default:
2683 break;
2684 }
2685}
2686
Sujith141b38b2009-02-04 08:10:07 +05302687static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002688 const struct ieee80211_tx_queue_params *params)
2689{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002690 struct ath_wiphy *aphy = hw->priv;
2691 struct ath_softc *sc = aphy->sc;
Sujithea9880f2008-08-07 10:53:10 +05302692 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002693 int ret = 0, qnum;
2694
2695 if (queue >= WME_NUM_AC)
2696 return 0;
2697
Sujith141b38b2009-02-04 08:10:07 +05302698 mutex_lock(&sc->mutex);
2699
Sujith1ffb0612009-03-30 15:28:46 +05302700 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2701
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002702 qi.tqi_aifs = params->aifs;
2703 qi.tqi_cwmin = params->cw_min;
2704 qi.tqi_cwmax = params->cw_max;
2705 qi.tqi_burstTime = params->txop;
2706 qnum = ath_get_hal_qnum(queue, sc);
2707
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002708 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Sujith04bd4632008-11-28 22:18:05 +05302709 "Configure tx [queue/halq] [%d/%d], "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002710 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
Sujith04bd4632008-11-28 22:18:05 +05302711 queue, qnum, params->aifs, params->cw_min,
2712 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002713
2714 ret = ath_txq_update(sc, qnum, &qi);
2715 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002716 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002717
Sujith141b38b2009-02-04 08:10:07 +05302718 mutex_unlock(&sc->mutex);
2719
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720 return ret;
2721}
2722
2723static int ath9k_set_key(struct ieee80211_hw *hw,
2724 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002725 struct ieee80211_vif *vif,
2726 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002727 struct ieee80211_key_conf *key)
2728{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002729 struct ath_wiphy *aphy = hw->priv;
2730 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002731 int ret = 0;
2732
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002733 if (modparam_nohwcrypt)
2734 return -ENOSPC;
2735
Sujith141b38b2009-02-04 08:10:07 +05302736 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302737 ath9k_ps_wakeup(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002738 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002739
2740 switch (cmd) {
2741 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002742 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002743 if (ret >= 0) {
2744 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002745 /* push IV and Michael MIC generation to stack */
2746 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302747 if (key->alg == ALG_TKIP)
2748 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002749 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2750 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002751 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002752 }
2753 break;
2754 case DISABLE_KEY:
2755 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002756 break;
2757 default:
2758 ret = -EINVAL;
2759 }
2760
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302761 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302762 mutex_unlock(&sc->mutex);
2763
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002764 return ret;
2765}
2766
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002767static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2768 struct ieee80211_vif *vif,
2769 struct ieee80211_bss_conf *bss_conf,
2770 u32 changed)
2771{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002772 struct ath_wiphy *aphy = hw->priv;
2773 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002774 struct ath_hw *ah = sc->sc_ah;
2775 struct ath_vif *avp = (void *)vif->drv_priv;
2776 u32 rfilt = 0;
2777 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002778
Sujith141b38b2009-02-04 08:10:07 +05302779 mutex_lock(&sc->mutex);
2780
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002781 /*
2782 * TODO: Need to decide which hw opmode to use for
2783 * multi-interface cases
2784 * XXX: This belongs into add_interface!
2785 */
2786 if (vif->type == NL80211_IFTYPE_AP &&
2787 ah->opmode != NL80211_IFTYPE_AP) {
2788 ah->opmode = NL80211_IFTYPE_STATION;
2789 ath9k_hw_setopmode(ah);
2790 memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
2791 sc->curaid = 0;
2792 ath9k_hw_write_associd(sc);
2793 /* Request full reset to get hw opmode changed properly */
2794 sc->sc_flags |= SC_OP_FULL_RESET;
2795 }
2796
2797 if ((changed & BSS_CHANGED_BSSID) &&
2798 !is_zero_ether_addr(bss_conf->bssid)) {
2799 switch (vif->type) {
2800 case NL80211_IFTYPE_STATION:
2801 case NL80211_IFTYPE_ADHOC:
2802 case NL80211_IFTYPE_MESH_POINT:
2803 /* Set BSSID */
2804 memcpy(sc->curbssid, bss_conf->bssid, ETH_ALEN);
2805 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
2806 sc->curaid = 0;
2807 ath9k_hw_write_associd(sc);
2808
2809 /* Set aggregation protection mode parameters */
2810 sc->config.ath_aggr_prot = 0;
2811
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002812 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002813 "RX filter 0x%x bssid %pM aid 0x%x\n",
2814 rfilt, sc->curbssid, sc->curaid);
2815
2816 /* need to reconfigure the beacon */
2817 sc->sc_flags &= ~SC_OP_BEACONS ;
2818
2819 break;
2820 default:
2821 break;
2822 }
2823 }
2824
2825 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2826 (vif->type == NL80211_IFTYPE_AP) ||
2827 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2828 if ((changed & BSS_CHANGED_BEACON) ||
2829 (changed & BSS_CHANGED_BEACON_ENABLED &&
2830 bss_conf->enable_beacon)) {
2831 /*
2832 * Allocate and setup the beacon frame.
2833 *
2834 * Stop any previous beacon DMA. This may be
2835 * necessary, for example, when an ibss merge
2836 * causes reconfiguration; we may be called
2837 * with beacon transmission active.
2838 */
2839 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2840
2841 error = ath_beacon_alloc(aphy, vif);
2842 if (!error)
2843 ath_beacon_config(sc, vif);
2844 }
2845 }
2846
2847 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2848 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2849 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2850 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2851 ath9k_hw_keysetmac(sc->sc_ah,
2852 (u16)i,
2853 sc->curbssid);
2854 }
2855
2856 /* Only legacy IBSS for now */
2857 if (vif->type == NL80211_IFTYPE_ADHOC)
2858 ath_update_chainmask(sc, 0);
2859
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002860 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002861 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002862 bss_conf->use_short_preamble);
2863 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302864 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002865 else
Sujith672840a2008-08-11 14:05:08 +05302866 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002867 }
2868
2869 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002870 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002871 bss_conf->use_cts_prot);
2872 if (bss_conf->use_cts_prot &&
2873 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302874 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002875 else
Sujith672840a2008-08-11 14:05:08 +05302876 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877 }
2878
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002879 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002880 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002881 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302882 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002883 }
Sujith141b38b2009-02-04 08:10:07 +05302884
Johannes Berg57c4d7b2009-04-23 16:10:04 +02002885 /*
2886 * The HW TSF has to be reset when the beacon interval changes.
2887 * We set the flag here, and ath_beacon_config_ap() would take this
2888 * into account when it gets called through the subsequent
2889 * config_interface() call - with IFCC_BEACON in the changed field.
2890 */
2891
2892 if (changed & BSS_CHANGED_BEACON_INT) {
2893 sc->sc_flags |= SC_OP_TSF_RESET;
2894 sc->beacon_interval = bss_conf->beacon_int;
2895 }
2896
Sujith141b38b2009-02-04 08:10:07 +05302897 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002898}
2899
2900static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2901{
2902 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002903 struct ath_wiphy *aphy = hw->priv;
2904 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002905
Sujith141b38b2009-02-04 08:10:07 +05302906 mutex_lock(&sc->mutex);
2907 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2908 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002909
2910 return tsf;
2911}
2912
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002913static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2914{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002915 struct ath_wiphy *aphy = hw->priv;
2916 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002917
Sujith141b38b2009-02-04 08:10:07 +05302918 mutex_lock(&sc->mutex);
2919 ath9k_hw_settsf64(sc->sc_ah, tsf);
2920 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002921}
2922
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002923static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2924{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002925 struct ath_wiphy *aphy = hw->priv;
2926 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002927
Sujith141b38b2009-02-04 08:10:07 +05302928 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002929
2930 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05302931 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07002932 ath9k_ps_restore(sc);
2933
Sujith141b38b2009-02-04 08:10:07 +05302934 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002935}
2936
2937static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05302938 enum ieee80211_ampdu_mlme_action action,
2939 struct ieee80211_sta *sta,
2940 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002941{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002942 struct ath_wiphy *aphy = hw->priv;
2943 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002944 int ret = 0;
2945
2946 switch (action) {
2947 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05302948 if (!(sc->sc_flags & SC_OP_RXAGGR))
2949 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002950 break;
2951 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002952 break;
2953 case IEEE80211_AMPDU_TX_START:
Sujithf83da962009-07-23 15:32:37 +05302954 ath_tx_aggr_start(sc, sta, tid, ssn);
2955 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002956 break;
2957 case IEEE80211_AMPDU_TX_STOP:
Sujithf83da962009-07-23 15:32:37 +05302958 ath_tx_aggr_stop(sc, sta, tid);
Johannes Berg17741cd2008-09-11 00:02:02 +02002959 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002960 break;
Johannes Bergb1720232009-03-23 17:28:39 +01002961 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05302962 ath_tx_aggr_resume(sc, sta, tid);
2963 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002964 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002965 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002966 }
2967
2968 return ret;
2969}
2970
Sujith0c98de62009-03-03 10:16:45 +05302971static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2972{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002973 struct ath_wiphy *aphy = hw->priv;
2974 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302975
Sujith3d832612009-08-21 12:00:28 +05302976 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002977 if (ath9k_wiphy_scanning(sc)) {
2978 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
2979 "same time\n");
2980 /*
2981 * Do not allow the concurrent scanning state for now. This
2982 * could be improved with scanning control moved into ath9k.
2983 */
Sujith3d832612009-08-21 12:00:28 +05302984 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002985 return;
2986 }
2987
2988 aphy->state = ATH_WIPHY_SCAN;
2989 ath9k_wiphy_pause_all_forced(sc, aphy);
2990
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302991 spin_lock_bh(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +05302992 sc->sc_flags |= SC_OP_SCANNING;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302993 spin_unlock_bh(&sc->ani_lock);
Sujith3d832612009-08-21 12:00:28 +05302994 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302995}
2996
2997static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2998{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002999 struct ath_wiphy *aphy = hw->priv;
3000 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05303001
Sujith3d832612009-08-21 12:00:28 +05303002 mutex_lock(&sc->mutex);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303003 spin_lock_bh(&sc->ani_lock);
Jouni Malinen8089cc42009-03-03 19:23:38 +02003004 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05303005 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05303006 sc->sc_flags |= SC_OP_FULL_RESET;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05303007 spin_unlock_bh(&sc->ani_lock);
Vivek Natarajand0bec342009-09-02 15:50:55 +05303008 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05303009 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05303010}
3011
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003012struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003013 .tx = ath9k_tx,
3014 .start = ath9k_start,
3015 .stop = ath9k_stop,
3016 .add_interface = ath9k_add_interface,
3017 .remove_interface = ath9k_remove_interface,
3018 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003019 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003020 .sta_notify = ath9k_sta_notify,
3021 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003022 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003023 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003024 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01003025 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003026 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02003027 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05303028 .sw_scan_start = ath9k_sw_scan_start,
3029 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05303030 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003031};
3032
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003033static struct {
3034 u32 version;
3035 const char * name;
3036} ath_mac_bb_names[] = {
3037 { AR_SREV_VERSION_5416_PCI, "5416" },
3038 { AR_SREV_VERSION_5416_PCIE, "5418" },
3039 { AR_SREV_VERSION_9100, "9100" },
3040 { AR_SREV_VERSION_9160, "9160" },
3041 { AR_SREV_VERSION_9280, "9280" },
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05303042 { AR_SREV_VERSION_9285, "9285" },
3043 { AR_SREV_VERSION_9287, "9287" }
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003044};
3045
3046static struct {
3047 u16 version;
3048 const char * name;
3049} ath_rf_names[] = {
3050 { 0, "5133" },
3051 { AR_RAD5133_SREV_MAJOR, "5133" },
3052 { AR_RAD5122_SREV_MAJOR, "5122" },
3053 { AR_RAD2133_SREV_MAJOR, "2133" },
3054 { AR_RAD2122_SREV_MAJOR, "2122" }
3055};
3056
3057/*
3058 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3059 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003060const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003061ath_mac_bb_name(u32 mac_bb_version)
3062{
3063 int i;
3064
3065 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3066 if (ath_mac_bb_names[i].version == mac_bb_version) {
3067 return ath_mac_bb_names[i].name;
3068 }
3069 }
3070
3071 return "????";
3072}
3073
3074/*
3075 * Return the RF name. "????" is returned if the RF is unknown.
3076 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003077const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01003078ath_rf_name(u16 rf_version)
3079{
3080 int i;
3081
3082 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3083 if (ath_rf_names[i].version == rf_version) {
3084 return ath_rf_names[i].name;
3085 }
3086 }
3087
3088 return "????";
3089}
3090
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003091static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003092{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303093 int error;
3094
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303095 /* Register rate control algorithm */
3096 error = ath_rate_control_register();
3097 if (error != 0) {
3098 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003099 "ath9k: Unable to register rate control "
3100 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303101 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003102 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303103 }
3104
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003105 error = ath9k_debug_create_root();
3106 if (error) {
3107 printk(KERN_ERR
3108 "ath9k: Unable to create debugfs root: %d\n",
3109 error);
3110 goto err_rate_unregister;
3111 }
3112
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003113 error = ath_pci_init();
3114 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003115 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08003116 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003117 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003118 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003119 }
3120
Gabor Juhos09329d32009-01-14 20:17:07 +01003121 error = ath_ahb_init();
3122 if (error < 0) {
3123 error = -ENODEV;
3124 goto err_pci_exit;
3125 }
3126
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003127 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003128
Gabor Juhos09329d32009-01-14 20:17:07 +01003129 err_pci_exit:
3130 ath_pci_exit();
3131
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003132 err_remove_root:
3133 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003134 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05303135 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003136 err_out:
3137 return error;
3138}
3139module_init(ath9k_init);
3140
3141static void __exit ath9k_exit(void)
3142{
Gabor Juhos09329d32009-01-14 20:17:07 +01003143 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003144 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01003145 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003146 ath_rate_control_unregister();
Sujith04bd4632008-11-28 22:18:05 +05303147 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003148}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01003149module_exit(ath9k_exit);