blob: 9564b73ded51f62e535adb3acd0c6ff74bbe363d [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. Rodriguezf078f202008-08-04 00:16:41 -070019
20#define ATH_PCI_VERSION "0.1"
21
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070022static char *dev_info = "ath9k";
23
24MODULE_AUTHOR("Atheros Communications");
25MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
26MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
27MODULE_LICENSE("Dual BSD/GPL");
28
Jouni Malinenb3bd89c2009-02-24 13:42:01 +020029static int modparam_nohwcrypt;
30module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
31MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
32
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080033/* We use the hw_value as an index into our private channel structure */
34
35#define CHAN2G(_freq, _idx) { \
36 .center_freq = (_freq), \
37 .hw_value = (_idx), \
38 .max_power = 30, \
39}
40
41#define CHAN5G(_freq, _idx) { \
42 .band = IEEE80211_BAND_5GHZ, \
43 .center_freq = (_freq), \
44 .hw_value = (_idx), \
45 .max_power = 30, \
46}
47
48/* Some 2 GHz radios are actually tunable on 2312-2732
49 * on 5 MHz steps, we support the channels which we know
50 * we have calibration data for all cards though to make
51 * this static */
52static struct ieee80211_channel ath9k_2ghz_chantable[] = {
53 CHAN2G(2412, 0), /* Channel 1 */
54 CHAN2G(2417, 1), /* Channel 2 */
55 CHAN2G(2422, 2), /* Channel 3 */
56 CHAN2G(2427, 3), /* Channel 4 */
57 CHAN2G(2432, 4), /* Channel 5 */
58 CHAN2G(2437, 5), /* Channel 6 */
59 CHAN2G(2442, 6), /* Channel 7 */
60 CHAN2G(2447, 7), /* Channel 8 */
61 CHAN2G(2452, 8), /* Channel 9 */
62 CHAN2G(2457, 9), /* Channel 10 */
63 CHAN2G(2462, 10), /* Channel 11 */
64 CHAN2G(2467, 11), /* Channel 12 */
65 CHAN2G(2472, 12), /* Channel 13 */
66 CHAN2G(2484, 13), /* Channel 14 */
67};
68
69/* Some 5 GHz radios are actually tunable on XXXX-YYYY
70 * on 5 MHz steps, we support the channels which we know
71 * we have calibration data for all cards though to make
72 * this static */
73static struct ieee80211_channel ath9k_5ghz_chantable[] = {
74 /* _We_ call this UNII 1 */
75 CHAN5G(5180, 14), /* Channel 36 */
76 CHAN5G(5200, 15), /* Channel 40 */
77 CHAN5G(5220, 16), /* Channel 44 */
78 CHAN5G(5240, 17), /* Channel 48 */
79 /* _We_ call this UNII 2 */
80 CHAN5G(5260, 18), /* Channel 52 */
81 CHAN5G(5280, 19), /* Channel 56 */
82 CHAN5G(5300, 20), /* Channel 60 */
83 CHAN5G(5320, 21), /* Channel 64 */
84 /* _We_ call this "Middle band" */
85 CHAN5G(5500, 22), /* Channel 100 */
86 CHAN5G(5520, 23), /* Channel 104 */
87 CHAN5G(5540, 24), /* Channel 108 */
88 CHAN5G(5560, 25), /* Channel 112 */
89 CHAN5G(5580, 26), /* Channel 116 */
90 CHAN5G(5600, 27), /* Channel 120 */
91 CHAN5G(5620, 28), /* Channel 124 */
92 CHAN5G(5640, 29), /* Channel 128 */
93 CHAN5G(5660, 30), /* Channel 132 */
94 CHAN5G(5680, 31), /* Channel 136 */
95 CHAN5G(5700, 32), /* Channel 140 */
96 /* _We_ call this UNII 3 */
97 CHAN5G(5745, 33), /* Channel 149 */
98 CHAN5G(5765, 34), /* Channel 153 */
99 CHAN5G(5785, 35), /* Channel 157 */
100 CHAN5G(5805, 36), /* Channel 161 */
101 CHAN5G(5825, 37), /* Channel 165 */
102};
103
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800104static void ath_cache_conf_rate(struct ath_softc *sc,
105 struct ieee80211_conf *conf)
Sujithff37e332008-11-24 12:07:55 +0530106{
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800107 switch (conf->channel->band) {
108 case IEEE80211_BAND_2GHZ:
109 if (conf_is_ht20(conf))
110 sc->cur_rate_table =
111 sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
112 else if (conf_is_ht40_minus(conf))
113 sc->cur_rate_table =
114 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
115 else if (conf_is_ht40_plus(conf))
116 sc->cur_rate_table =
117 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800118 else
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800119 sc->cur_rate_table =
120 sc->hw_rate_table[ATH9K_MODE_11G];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800121 break;
122 case IEEE80211_BAND_5GHZ:
123 if (conf_is_ht20(conf))
124 sc->cur_rate_table =
125 sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
126 else if (conf_is_ht40_minus(conf))
127 sc->cur_rate_table =
128 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
129 else if (conf_is_ht40_plus(conf))
130 sc->cur_rate_table =
131 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
132 else
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800133 sc->cur_rate_table =
134 sc->hw_rate_table[ATH9K_MODE_11A];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800135 break;
136 default:
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800137 BUG_ON(1);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800138 break;
139 }
Sujithff37e332008-11-24 12:07:55 +0530140}
141
142static void ath_update_txpow(struct ath_softc *sc)
143{
Sujithcbe61d82009-02-09 13:27:12 +0530144 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530145 u32 txpow;
146
Sujith17d79042009-02-09 13:27:03 +0530147 if (sc->curtxpow != sc->config.txpowlimit) {
148 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +0530149 /* read back in case value is clamped */
150 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
Sujith17d79042009-02-09 13:27:03 +0530151 sc->curtxpow = txpow;
Sujithff37e332008-11-24 12:07:55 +0530152 }
153}
154
155static u8 parse_mpdudensity(u8 mpdudensity)
156{
157 /*
158 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
159 * 0 for no restriction
160 * 1 for 1/4 us
161 * 2 for 1/2 us
162 * 3 for 1 us
163 * 4 for 2 us
164 * 5 for 4 us
165 * 6 for 8 us
166 * 7 for 16 us
167 */
168 switch (mpdudensity) {
169 case 0:
170 return 0;
171 case 1:
172 case 2:
173 case 3:
174 /* Our lower layer calculations limit our precision to
175 1 microsecond */
176 return 1;
177 case 4:
178 return 2;
179 case 5:
180 return 4;
181 case 6:
182 return 8;
183 case 7:
184 return 16;
185 default:
186 return 0;
187 }
188}
189
190static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
191{
192 struct ath_rate_table *rate_table = NULL;
193 struct ieee80211_supported_band *sband;
194 struct ieee80211_rate *rate;
195 int i, maxrates;
196
197 switch (band) {
198 case IEEE80211_BAND_2GHZ:
199 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
200 break;
201 case IEEE80211_BAND_5GHZ:
202 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
203 break;
204 default:
205 break;
206 }
207
208 if (rate_table == NULL)
209 return;
210
211 sband = &sc->sbands[band];
212 rate = sc->rates[band];
213
214 if (rate_table->rate_cnt > ATH_RATE_MAX)
215 maxrates = ATH_RATE_MAX;
216 else
217 maxrates = rate_table->rate_cnt;
218
219 for (i = 0; i < maxrates; i++) {
220 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
221 rate[i].hw_value = rate_table->info[i].ratecode;
Sujithf46730d2009-01-27 13:51:03 +0530222 if (rate_table->info[i].short_preamble) {
223 rate[i].hw_value_short = rate_table->info[i].ratecode |
224 rate_table->info[i].short_preamble;
225 rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
226 }
Sujithff37e332008-11-24 12:07:55 +0530227 sband->n_bitrates++;
Sujithf46730d2009-01-27 13:51:03 +0530228
Sujith04bd4632008-11-28 22:18:05 +0530229 DPRINTF(sc, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
230 rate[i].bitrate / 10, rate[i].hw_value);
Sujithff37e332008-11-24 12:07:55 +0530231 }
232}
233
Sujithff37e332008-11-24 12:07:55 +0530234/*
235 * Set/change channels. If the channel is really being changed, it's done
236 * by reseting the chip. To accomplish this we must first cleanup any pending
237 * DMA, then restart stuff.
238*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200239int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
240 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530241{
Sujithcbe61d82009-02-09 13:27:12 +0530242 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530243 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800244 struct ieee80211_channel *channel = hw->conf.channel;
245 int r;
Sujithff37e332008-11-24 12:07:55 +0530246
247 if (sc->sc_flags & SC_OP_INVALID)
248 return -EIO;
249
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530250 ath9k_ps_wakeup(sc);
251
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800252 /*
253 * This is only performed if the channel settings have
254 * actually changed.
255 *
256 * To switch channels clear any pending DMA operations;
257 * wait long enough for the RX fifo to drain, reset the
258 * hardware at the new frequency, and then re-enable
259 * the relevant bits of the h/w.
260 */
261 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530262 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800263 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530264
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800265 /* XXX: do not flush receive queue here. We don't want
266 * to flush data frames already in queue because of
267 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530268
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800269 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
270 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530271
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800272 DPRINTF(sc, ATH_DBG_CONFIG,
273 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
Sujith2660b812009-02-09 13:27:26 +0530274 sc->sc_ah->curchan->channel,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800275 channel->center_freq, sc->tx_chan_width);
Sujith99405f92008-11-24 12:08:35 +0530276
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800277 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800278
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800279 r = ath9k_hw_reset(ah, hchan, fastcc);
280 if (r) {
281 DPRINTF(sc, ATH_DBG_FATAL,
282 "Unable to reset channel (%u Mhz) "
283 "reset status %u\n",
284 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530285 spin_unlock_bh(&sc->sc_resetlock);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800286 return r;
Sujithff37e332008-11-24 12:07:55 +0530287 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800288 spin_unlock_bh(&sc->sc_resetlock);
289
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800290 sc->sc_flags &= ~SC_OP_FULL_RESET;
291
292 if (ath_startrecv(sc) != 0) {
293 DPRINTF(sc, ATH_DBG_FATAL,
294 "Unable to restart recv logic\n");
295 return -EIO;
296 }
297
298 ath_cache_conf_rate(sc, &hw->conf);
299 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530300 ath9k_hw_set_interrupts(ah, sc->imask);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530301 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530302 return 0;
303}
304
305/*
306 * This routine performs the periodic noise floor calibration function
307 * that is used to adjust and optimize the chip performance. This
308 * takes environmental changes (location, temperature) into account.
309 * When the task is complete, it reschedules itself depending on the
310 * appropriate interval that was calculated.
311 */
312static void ath_ani_calibrate(unsigned long data)
313{
Sujith20977d32009-02-20 15:13:28 +0530314 struct ath_softc *sc = (struct ath_softc *)data;
315 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530316 bool longcal = false;
317 bool shortcal = false;
318 bool aniflag = false;
319 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530320 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530321
Sujith20977d32009-02-20 15:13:28 +0530322 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
323 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530324
325 /*
326 * don't calibrate when we're scanning.
327 * we are most likely not on our home channel.
328 */
Sujith0c98de62009-03-03 10:16:45 +0530329 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530330 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530331
332 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530333 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530334 longcal = true;
Sujith04bd4632008-11-28 22:18:05 +0530335 DPRINTF(sc, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530336 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530337 }
338
Sujith17d79042009-02-09 13:27:03 +0530339 /* Short calibration applies only while caldone is false */
340 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530341 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530342 shortcal = true;
Sujith04bd4632008-11-28 22:18:05 +0530343 DPRINTF(sc, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530344 sc->ani.shortcal_timer = timestamp;
345 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530346 }
347 } else {
Sujith17d79042009-02-09 13:27:03 +0530348 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530349 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530350 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
351 if (sc->ani.caldone)
352 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530353 }
354 }
355
356 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530357 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530358 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530359 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530360 }
361
362 /* Skip all processing if there's nothing to do. */
363 if (longcal || shortcal || aniflag) {
364 /* Call ANI routine if necessary */
365 if (aniflag)
Sujith20977d32009-02-20 15:13:28 +0530366 ath9k_hw_ani_monitor(ah, &sc->nodestats, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530367
368 /* Perform calibration if necessary */
369 if (longcal || shortcal) {
370 bool iscaldone = false;
371
Sujith2660b812009-02-09 13:27:26 +0530372 if (ath9k_hw_calibrate(ah, ah->curchan,
Sujith17d79042009-02-09 13:27:03 +0530373 sc->rx_chainmask, longcal,
Sujithff37e332008-11-24 12:07:55 +0530374 &iscaldone)) {
375 if (longcal)
Sujith17d79042009-02-09 13:27:03 +0530376 sc->ani.noise_floor =
Sujithff37e332008-11-24 12:07:55 +0530377 ath9k_hw_getchan_noise(ah,
Sujith2660b812009-02-09 13:27:26 +0530378 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530379
380 DPRINTF(sc, ATH_DBG_ANI,
Sujith04bd4632008-11-28 22:18:05 +0530381 "calibrate chan %u/%x nf: %d\n",
Sujith2660b812009-02-09 13:27:26 +0530382 ah->curchan->channel,
383 ah->curchan->channelFlags,
Sujith17d79042009-02-09 13:27:03 +0530384 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530385 } else {
386 DPRINTF(sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +0530387 "calibrate chan %u/%x failed\n",
Sujith2660b812009-02-09 13:27:26 +0530388 ah->curchan->channel,
389 ah->curchan->channelFlags);
Sujithff37e332008-11-24 12:07:55 +0530390 }
Sujith17d79042009-02-09 13:27:03 +0530391 sc->ani.caldone = iscaldone;
Sujithff37e332008-11-24 12:07:55 +0530392 }
393 }
394
Sujith20977d32009-02-20 15:13:28 +0530395set_timer:
Sujithff37e332008-11-24 12:07:55 +0530396 /*
397 * Set timer interval based on previous results.
398 * The interval must be the shortest necessary to satisfy ANI,
399 * short calibration and long calibration.
400 */
Sujithaac92072008-12-02 18:37:54 +0530401 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530402 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530403 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530404 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530405 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530406
Sujith17d79042009-02-09 13:27:03 +0530407 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530408}
409
Sujith415f7382009-04-13 21:56:46 +0530410static void ath_start_ani(struct ath_softc *sc)
411{
412 unsigned long timestamp = jiffies_to_msecs(jiffies);
413
414 sc->ani.longcal_timer = timestamp;
415 sc->ani.shortcal_timer = timestamp;
416 sc->ani.checkani_timer = timestamp;
417
418 mod_timer(&sc->ani.timer,
419 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
420}
421
Sujithff37e332008-11-24 12:07:55 +0530422/*
423 * Update tx/rx chainmask. For legacy association,
424 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530425 * the chainmask configuration, for bt coexistence, use
426 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530427 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200428void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530429{
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530430 if (is_ht ||
Sujith2660b812009-02-09 13:27:26 +0530431 (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)) {
432 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
433 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530434 } else {
Sujith17d79042009-02-09 13:27:03 +0530435 sc->tx_chainmask = 1;
436 sc->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530437 }
438
Sujith04bd4632008-11-28 22:18:05 +0530439 DPRINTF(sc, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
Sujith17d79042009-02-09 13:27:03 +0530440 sc->tx_chainmask, sc->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530441}
442
443static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
444{
445 struct ath_node *an;
446
447 an = (struct ath_node *)sta->drv_priv;
448
Sujith87792ef2009-03-30 15:28:48 +0530449 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530450 ath_tx_node_init(sc, an);
Sujith87792ef2009-03-30 15:28:48 +0530451 an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
452 sta->ht_cap.ampdu_factor);
453 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
454 }
Sujithff37e332008-11-24 12:07:55 +0530455}
456
457static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
458{
459 struct ath_node *an = (struct ath_node *)sta->drv_priv;
460
461 if (sc->sc_flags & SC_OP_TXAGGR)
462 ath_tx_node_cleanup(sc, an);
463}
464
465static void ath9k_tasklet(unsigned long data)
466{
467 struct ath_softc *sc = (struct ath_softc *)data;
Sujith17d79042009-02-09 13:27:03 +0530468 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530469
470 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530471 ath_reset(sc, false);
472 return;
Sujithff37e332008-11-24 12:07:55 +0530473 }
474
Sujith063d8be2009-03-30 15:28:49 +0530475 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
476 spin_lock_bh(&sc->rx.rxflushlock);
477 ath_rx_tasklet(sc, 0);
478 spin_unlock_bh(&sc->rx.rxflushlock);
479 }
480
481 if (status & ATH9K_INT_TX)
482 ath_tx_tasklet(sc);
483
Sujithff37e332008-11-24 12:07:55 +0530484 /* re-enable hardware interrupt */
Sujith17d79042009-02-09 13:27:03 +0530485 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +0530486}
487
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100488irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530489{
Sujith063d8be2009-03-30 15:28:49 +0530490#define SCHED_INTR ( \
491 ATH9K_INT_FATAL | \
492 ATH9K_INT_RXORN | \
493 ATH9K_INT_RXEOL | \
494 ATH9K_INT_RX | \
495 ATH9K_INT_TX | \
496 ATH9K_INT_BMISS | \
497 ATH9K_INT_CST | \
498 ATH9K_INT_TSFOOR)
499
Sujithff37e332008-11-24 12:07:55 +0530500 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530501 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530502 enum ath9k_int status;
503 bool sched = false;
504
Sujith063d8be2009-03-30 15:28:49 +0530505 /*
506 * The hardware is not ready/present, don't
507 * touch anything. Note this can happen early
508 * on if the IRQ is shared.
509 */
510 if (sc->sc_flags & SC_OP_INVALID)
511 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530512
Sujith063d8be2009-03-30 15:28:49 +0530513 ath9k_ps_wakeup(sc);
Sujithff37e332008-11-24 12:07:55 +0530514
Sujith063d8be2009-03-30 15:28:49 +0530515 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530516
Sujith063d8be2009-03-30 15:28:49 +0530517 if (!ath9k_hw_intrpend(ah)) {
Vivek Natarajan541d8dd2009-03-02 20:25:14 +0530518 ath9k_ps_restore(sc);
Sujith063d8be2009-03-30 15:28:49 +0530519 return IRQ_NONE;
520 }
Sujithff37e332008-11-24 12:07:55 +0530521
Sujith063d8be2009-03-30 15:28:49 +0530522 /*
523 * Figure out the reason(s) for the interrupt. Note
524 * that the hal returns a pseudo-ISR that may include
525 * bits we haven't explicitly enabled so we mask the
526 * value to insure we only process bits we requested.
527 */
528 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
529 status &= sc->imask; /* discard unasked-for bits */
530
531 /*
532 * If there are no status bits set, then this interrupt was not
533 * for me (should have been caught above).
534 */
535 if (!status) {
536 ath9k_ps_restore(sc);
537 return IRQ_NONE;
538 }
539
540 /* Cache the status */
541 sc->intrstatus = status;
542
543 if (status & SCHED_INTR)
544 sched = true;
545
546 /*
547 * If a FATAL or RXORN interrupt is received, we have to reset the
548 * chip immediately.
549 */
550 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
551 goto chip_reset;
552
553 if (status & ATH9K_INT_SWBA)
554 tasklet_schedule(&sc->bcon_tasklet);
555
556 if (status & ATH9K_INT_TXURN)
557 ath9k_hw_updatetxtriglevel(ah, true);
558
559 if (status & ATH9K_INT_MIB) {
560 /*
561 * Disable interrupts until we service the MIB
562 * interrupt; otherwise it will continue to
563 * fire.
564 */
565 ath9k_hw_set_interrupts(ah, 0);
566 /*
567 * Let the hal handle the event. We assume
568 * it will clear whatever condition caused
569 * the interrupt.
570 */
571 ath9k_hw_procmibevent(ah, &sc->nodestats);
572 ath9k_hw_set_interrupts(ah, sc->imask);
573 }
574
575 if (status & ATH9K_INT_TIM_TIMER) {
576 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
577 /* Clear RxAbort bit so that we can
578 * receive frames */
579 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
580 ath9k_hw_setrxabort(ah, 0);
581 sched = true;
582 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
583 }
584 }
585
586chip_reset:
587
588 ath9k_ps_restore(sc);
Sujith817e11d2008-12-07 21:42:44 +0530589 ath_debug_stat_interrupt(sc, status);
590
Sujithff37e332008-11-24 12:07:55 +0530591 if (sched) {
592 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530593 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530594 tasklet_schedule(&sc->intr_tq);
595 }
596
597 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530598
599#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530600}
601
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700602static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530603 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530604 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700605{
606 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700607
608 switch (chan->band) {
609 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530610 switch(channel_type) {
611 case NL80211_CHAN_NO_HT:
612 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530614 break;
615 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530617 break;
618 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530620 break;
621 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700622 break;
623 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530624 switch(channel_type) {
625 case NL80211_CHAN_NO_HT:
626 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700627 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530628 break;
629 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530631 break;
632 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530634 break;
635 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700636 break;
637 default:
638 break;
639 }
640
641 return chanmode;
642}
643
Jouni Malinen6ace2892008-12-17 13:32:17 +0200644static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200645 struct ath9k_keyval *hk, const u8 *addr,
646 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200648 const u8 *key_rxmic;
649 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650
Jouni Malinen6ace2892008-12-17 13:32:17 +0200651 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
652 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700653
654 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200655 /*
656 * Group key installation - only two key cache entries are used
657 * regardless of splitmic capability since group key is only
658 * used either for TX or RX.
659 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200660 if (authenticator) {
661 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
662 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
663 } else {
664 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
665 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
666 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200667 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700668 }
Sujith17d79042009-02-09 13:27:03 +0530669 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200670 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700671 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
672 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200673 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700674 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200675
676 /* Separate key cache entries for TX and RX */
677
678 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700679 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200680 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
681 /* TX MIC entry failed. No need to proceed further */
Sujithd8baa932009-03-30 15:28:25 +0530682 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +0530683 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700684 return 0;
685 }
686
687 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
688 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200689 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200690}
691
692static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
693{
694 int i;
695
Sujith17d79042009-02-09 13:27:03 +0530696 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
697 if (test_bit(i, sc->keymap) ||
698 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200699 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530700 if (sc->splitmic &&
701 (test_bit(i + 32, sc->keymap) ||
702 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200703 continue; /* At least one part of TKIP key allocated */
704
705 /* Found a free slot for a TKIP key */
706 return i;
707 }
708 return -1;
709}
710
711static int ath_reserve_key_cache_slot(struct ath_softc *sc)
712{
713 int i;
714
715 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530716 if (sc->splitmic) {
717 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
718 if (!test_bit(i, sc->keymap) &&
719 (test_bit(i + 32, sc->keymap) ||
720 test_bit(i + 64, sc->keymap) ||
721 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200722 return i;
Sujith17d79042009-02-09 13:27:03 +0530723 if (!test_bit(i + 32, sc->keymap) &&
724 (test_bit(i, sc->keymap) ||
725 test_bit(i + 64, sc->keymap) ||
726 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200727 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530728 if (!test_bit(i + 64, sc->keymap) &&
729 (test_bit(i , sc->keymap) ||
730 test_bit(i + 32, sc->keymap) ||
731 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200732 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530733 if (!test_bit(i + 64 + 32, sc->keymap) &&
734 (test_bit(i, sc->keymap) ||
735 test_bit(i + 32, sc->keymap) ||
736 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200737 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200738 }
739 } else {
Sujith17d79042009-02-09 13:27:03 +0530740 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
741 if (!test_bit(i, sc->keymap) &&
742 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200743 return i;
Sujith17d79042009-02-09 13:27:03 +0530744 if (test_bit(i, sc->keymap) &&
745 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200746 return i + 64;
747 }
748 }
749
750 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530751 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200752 /* Do not allow slots that could be needed for TKIP group keys
753 * to be used. This limitation could be removed if we know that
754 * TKIP will not be used. */
755 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
756 continue;
Sujith17d79042009-02-09 13:27:03 +0530757 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200758 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
759 continue;
760 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
761 continue;
762 }
763
Sujith17d79042009-02-09 13:27:03 +0530764 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200765 return i; /* Found a free slot for a key */
766 }
767
768 /* No free slot found */
769 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700770}
771
772static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200773 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100774 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700775 struct ieee80211_key_conf *key)
776{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700777 struct ath9k_keyval hk;
778 const u8 *mac = NULL;
779 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200780 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700781
782 memset(&hk, 0, sizeof(hk));
783
784 switch (key->alg) {
785 case ALG_WEP:
786 hk.kv_type = ATH9K_CIPHER_WEP;
787 break;
788 case ALG_TKIP:
789 hk.kv_type = ATH9K_CIPHER_TKIP;
790 break;
791 case ALG_CCMP:
792 hk.kv_type = ATH9K_CIPHER_AES_CCM;
793 break;
794 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200795 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700796 }
797
Jouni Malinen6ace2892008-12-17 13:32:17 +0200798 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700799 memcpy(hk.kv_val, key->key, key->keylen);
800
Jouni Malinen6ace2892008-12-17 13:32:17 +0200801 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
802 /* For now, use the default keys for broadcast keys. This may
803 * need to change with virtual interfaces. */
804 idx = key->keyidx;
805 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100806 if (WARN_ON(!sta))
807 return -EOPNOTSUPP;
808 mac = sta->addr;
809
Jouni Malinen6ace2892008-12-17 13:32:17 +0200810 if (vif->type != NL80211_IFTYPE_AP) {
811 /* Only keyidx 0 should be used with unicast key, but
812 * allow this for client mode for now. */
813 idx = key->keyidx;
814 } else
815 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700816 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100817 if (WARN_ON(!sta))
818 return -EOPNOTSUPP;
819 mac = sta->addr;
820
Jouni Malinen6ace2892008-12-17 13:32:17 +0200821 if (key->alg == ALG_TKIP)
822 idx = ath_reserve_key_cache_slot_tkip(sc);
823 else
824 idx = ath_reserve_key_cache_slot(sc);
825 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200826 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 }
828
829 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200830 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
831 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700832 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200833 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700834
835 if (!ret)
836 return -EIO;
837
Sujith17d79042009-02-09 13:27:03 +0530838 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200839 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530840 set_bit(idx + 64, sc->keymap);
841 if (sc->splitmic) {
842 set_bit(idx + 32, sc->keymap);
843 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200844 }
845 }
846
847 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700848}
849
850static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
851{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200852 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
853 if (key->hw_key_idx < IEEE80211_WEP_NKID)
854 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700855
Sujith17d79042009-02-09 13:27:03 +0530856 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200857 if (key->alg != ALG_TKIP)
858 return;
859
Sujith17d79042009-02-09 13:27:03 +0530860 clear_bit(key->hw_key_idx + 64, sc->keymap);
861 if (sc->splitmic) {
862 clear_bit(key->hw_key_idx + 32, sc->keymap);
863 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200864 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700865}
866
Sujitheb2599c2009-01-23 11:20:44 +0530867static void setup_ht_cap(struct ath_softc *sc,
868 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700869{
Sujith60653672008-08-14 13:28:02 +0530870#define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
871#define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700872
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200873 ht_info->ht_supported = true;
874 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
875 IEEE80211_HT_CAP_SM_PS |
876 IEEE80211_HT_CAP_SGI_40 |
877 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700878
Sujith60653672008-08-14 13:28:02 +0530879 ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
880 ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530881
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200882 /* set up supported mcs set */
883 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Sujitheb2599c2009-01-23 11:20:44 +0530884
Sujith17d79042009-02-09 13:27:03 +0530885 switch(sc->rx_chainmask) {
Sujitheb2599c2009-01-23 11:20:44 +0530886 case 1:
887 ht_info->mcs.rx_mask[0] = 0xff;
888 break;
Sujith3c457262009-01-27 10:55:31 +0530889 case 3:
Sujitheb2599c2009-01-23 11:20:44 +0530890 case 5:
891 case 7:
892 default:
893 ht_info->mcs.rx_mask[0] = 0xff;
894 ht_info->mcs.rx_mask[1] = 0xff;
895 break;
896 }
897
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200898 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700899}
900
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530901static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530902 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530903 struct ieee80211_bss_conf *bss_conf)
904{
Sujith17d79042009-02-09 13:27:03 +0530905 struct ath_vif *avp = (void *)vif->drv_priv;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530906
907 if (bss_conf->assoc) {
Sujith094d05d2008-12-12 11:57:43 +0530908 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
Sujith17d79042009-02-09 13:27:03 +0530909 bss_conf->aid, sc->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530910
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530911 /* New association, store aid */
Colin McCabed97809d2008-12-01 13:38:55 -0800912 if (avp->av_opmode == NL80211_IFTYPE_STATION) {
Sujith17d79042009-02-09 13:27:03 +0530913 sc->curaid = bss_conf->aid;
Sujithba52da52009-02-09 13:27:10 +0530914 ath9k_hw_write_associd(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530915 }
916
917 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200918 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530919
920 /* Reset rssi stats */
Sujith17d79042009-02-09 13:27:03 +0530921 sc->nodestats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
922 sc->nodestats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
923 sc->nodestats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
924 sc->nodestats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530925
Sujith415f7382009-04-13 21:56:46 +0530926 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530927 } else {
Sujith1ffb0612009-03-30 15:28:46 +0530928 DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Sujith17d79042009-02-09 13:27:03 +0530929 sc->curaid = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530930 }
931}
932
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530933/********************************/
934/* LED functions */
935/********************************/
936
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530937static void ath_led_blink_work(struct work_struct *work)
938{
939 struct ath_softc *sc = container_of(work, struct ath_softc,
940 ath_led_blink_work.work);
941
942 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
943 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530944
945 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
946 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
947 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
948 else
949 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
950 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530951
952 queue_delayed_work(sc->hw->workqueue, &sc->ath_led_blink_work,
953 (sc->sc_flags & SC_OP_LED_ON) ?
954 msecs_to_jiffies(sc->led_off_duration) :
955 msecs_to_jiffies(sc->led_on_duration));
956
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530957 sc->led_on_duration = sc->led_on_cnt ?
958 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
959 ATH_LED_ON_DURATION_IDLE;
960 sc->led_off_duration = sc->led_off_cnt ?
961 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
962 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530963 sc->led_on_cnt = sc->led_off_cnt = 0;
964 if (sc->sc_flags & SC_OP_LED_ON)
965 sc->sc_flags &= ~SC_OP_LED_ON;
966 else
967 sc->sc_flags |= SC_OP_LED_ON;
968}
969
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530970static void ath_led_brightness(struct led_classdev *led_cdev,
971 enum led_brightness brightness)
972{
973 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
974 struct ath_softc *sc = led->sc;
975
976 switch (brightness) {
977 case LED_OFF:
978 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530979 led->led_type == ATH_LED_RADIO) {
980 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
981 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530982 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530983 if (led->led_type == ATH_LED_RADIO)
984 sc->sc_flags &= ~SC_OP_LED_ON;
985 } else {
986 sc->led_off_cnt++;
987 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530988 break;
989 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530990 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530991 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530992 queue_delayed_work(sc->hw->workqueue,
993 &sc->ath_led_blink_work, 0);
994 } else if (led->led_type == ATH_LED_RADIO) {
995 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
996 sc->sc_flags |= SC_OP_LED_ON;
997 } else {
998 sc->led_on_cnt++;
999 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301000 break;
1001 default:
1002 break;
1003 }
1004}
1005
1006static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1007 char *trigger)
1008{
1009 int ret;
1010
1011 led->sc = sc;
1012 led->led_cdev.name = led->name;
1013 led->led_cdev.default_trigger = trigger;
1014 led->led_cdev.brightness_set = ath_led_brightness;
1015
1016 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1017 if (ret)
1018 DPRINTF(sc, ATH_DBG_FATAL,
1019 "Failed to register led:%s", led->name);
1020 else
1021 led->registered = 1;
1022 return ret;
1023}
1024
1025static void ath_unregister_led(struct ath_led *led)
1026{
1027 if (led->registered) {
1028 led_classdev_unregister(&led->led_cdev);
1029 led->registered = 0;
1030 }
1031}
1032
1033static void ath_deinit_leds(struct ath_softc *sc)
1034{
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301035 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301036 ath_unregister_led(&sc->assoc_led);
1037 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1038 ath_unregister_led(&sc->tx_led);
1039 ath_unregister_led(&sc->rx_led);
1040 ath_unregister_led(&sc->radio_led);
1041 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1042}
1043
1044static void ath_init_leds(struct ath_softc *sc)
1045{
1046 char *trigger;
1047 int ret;
1048
1049 /* Configure gpio 1 for output */
1050 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
1051 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1052 /* LED off, active low */
1053 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1054
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301055 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1056
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301057 trigger = ieee80211_get_radio_led_name(sc->hw);
1058 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001059 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301060 ret = ath_register_led(sc, &sc->radio_led, trigger);
1061 sc->radio_led.led_type = ATH_LED_RADIO;
1062 if (ret)
1063 goto fail;
1064
1065 trigger = ieee80211_get_assoc_led_name(sc->hw);
1066 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001067 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301068 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1069 sc->assoc_led.led_type = ATH_LED_ASSOC;
1070 if (ret)
1071 goto fail;
1072
1073 trigger = ieee80211_get_tx_led_name(sc->hw);
1074 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001075 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301076 ret = ath_register_led(sc, &sc->tx_led, trigger);
1077 sc->tx_led.led_type = ATH_LED_TX;
1078 if (ret)
1079 goto fail;
1080
1081 trigger = ieee80211_get_rx_led_name(sc->hw);
1082 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001083 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301084 ret = ath_register_led(sc, &sc->rx_led, trigger);
1085 sc->rx_led.led_type = ATH_LED_RX;
1086 if (ret)
1087 goto fail;
1088
1089 return;
1090
1091fail:
1092 ath_deinit_leds(sc);
1093}
1094
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001095void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301096{
Sujithcbe61d82009-02-09 13:27:12 +05301097 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001098 struct ieee80211_channel *channel = sc->hw->conf.channel;
1099 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301100
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301101 ath9k_ps_wakeup(sc);
Sujithd2f5b3a2009-04-13 21:56:25 +05301102 ath9k_hw_configpcipowersave(ah, 0);
1103
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301104 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301105 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001106 if (r) {
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301107 DPRINTF(sc, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001108 "Unable to reset channel %u (%uMhz) ",
1109 "reset status %u\n",
1110 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301111 }
1112 spin_unlock_bh(&sc->sc_resetlock);
1113
1114 ath_update_txpow(sc);
1115 if (ath_startrecv(sc) != 0) {
1116 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301117 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301118 return;
1119 }
1120
1121 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001122 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301123
1124 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301125 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301126
1127 /* Enable LED */
1128 ath9k_hw_cfg_output(ah, ATH_LED_PIN,
1129 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1130 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
1131
1132 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301133 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301134}
1135
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001136void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301137{
Sujithcbe61d82009-02-09 13:27:12 +05301138 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001139 struct ieee80211_channel *channel = sc->hw->conf.channel;
1140 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301141
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301142 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301143 ieee80211_stop_queues(sc->hw);
1144
1145 /* Disable LED */
1146 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1);
1147 ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN);
1148
1149 /* Disable interrupts */
1150 ath9k_hw_set_interrupts(ah, 0);
1151
Sujith043a0402009-01-16 21:38:47 +05301152 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301153 ath_stoprecv(sc); /* turn off frame recv */
1154 ath_flushrecv(sc); /* flush recv queue */
1155
1156 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301157 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001158 if (r) {
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301159 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301160 "Unable to reset channel %u (%uMhz) "
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001161 "reset status %u\n",
1162 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301163 }
1164 spin_unlock_bh(&sc->sc_resetlock);
1165
1166 ath9k_hw_phy_disable(ah);
Sujithd2f5b3a2009-04-13 21:56:25 +05301167 ath9k_hw_configpcipowersave(ah, 1);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301168 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301169 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301170}
1171
Gabor Juhos5077fd32009-03-06 11:17:55 +01001172#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
1173
1174/*******************/
1175/* Rfkill */
1176/*******************/
1177
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301178static bool ath_is_rfkill_set(struct ath_softc *sc)
1179{
Sujithcbe61d82009-02-09 13:27:12 +05301180 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301181
Sujith2660b812009-02-09 13:27:26 +05301182 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1183 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301184}
1185
1186/* h/w rfkill poll function */
1187static void ath_rfkill_poll(struct work_struct *work)
1188{
1189 struct ath_softc *sc = container_of(work, struct ath_softc,
1190 rf_kill.rfkill_poll.work);
1191 bool radio_on;
1192
1193 if (sc->sc_flags & SC_OP_INVALID)
1194 return;
1195
1196 radio_on = !ath_is_rfkill_set(sc);
1197
1198 /*
1199 * enable/disable radio only when there is a
1200 * state change in RF switch
1201 */
1202 if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) {
1203 enum rfkill_state state;
1204
1205 if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) {
1206 state = radio_on ? RFKILL_STATE_SOFT_BLOCKED
1207 : RFKILL_STATE_HARD_BLOCKED;
1208 } else if (radio_on) {
1209 ath_radio_enable(sc);
1210 state = RFKILL_STATE_UNBLOCKED;
1211 } else {
1212 ath_radio_disable(sc);
1213 state = RFKILL_STATE_HARD_BLOCKED;
1214 }
1215
1216 if (state == RFKILL_STATE_HARD_BLOCKED)
1217 sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED;
1218 else
1219 sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED;
1220
1221 rfkill_force_state(sc->rf_kill.rfkill, state);
1222 }
1223
1224 queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll,
1225 msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL));
1226}
1227
1228/* s/w rfkill handler */
1229static int ath_sw_toggle_radio(void *data, enum rfkill_state state)
1230{
1231 struct ath_softc *sc = data;
1232
1233 switch (state) {
1234 case RFKILL_STATE_SOFT_BLOCKED:
1235 if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED |
1236 SC_OP_RFKILL_SW_BLOCKED)))
1237 ath_radio_disable(sc);
1238 sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED;
1239 return 0;
1240 case RFKILL_STATE_UNBLOCKED:
1241 if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) {
1242 sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED;
1243 if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) {
1244 DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the"
Sujith04bd4632008-11-28 22:18:05 +05301245 "radio as it is disabled by h/w\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301246 return -EPERM;
1247 }
1248 ath_radio_enable(sc);
1249 }
1250 return 0;
1251 default:
1252 return -EINVAL;
1253 }
1254}
1255
1256/* Init s/w rfkill */
1257static int ath_init_sw_rfkill(struct ath_softc *sc)
1258{
1259 sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy),
1260 RFKILL_TYPE_WLAN);
1261 if (!sc->rf_kill.rfkill) {
1262 DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n");
1263 return -ENOMEM;
1264 }
1265
1266 snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001267 "ath9k-%s::rfkill", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301268 sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name;
1269 sc->rf_kill.rfkill->data = sc;
1270 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
1271 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301272
1273 return 0;
1274}
1275
1276/* Deinitialize rfkill */
1277static void ath_deinit_rfkill(struct ath_softc *sc)
1278{
Sujith2660b812009-02-09 13:27:26 +05301279 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301280 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1281
1282 if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) {
1283 rfkill_unregister(sc->rf_kill.rfkill);
1284 sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED;
1285 sc->rf_kill.rfkill = NULL;
1286 }
1287}
Sujith9c84b792008-10-29 10:17:13 +05301288
1289static int ath_start_rfkill_poll(struct ath_softc *sc)
1290{
Sujith2660b812009-02-09 13:27:26 +05301291 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Sujith9c84b792008-10-29 10:17:13 +05301292 queue_delayed_work(sc->hw->workqueue,
1293 &sc->rf_kill.rfkill_poll, 0);
1294
1295 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
1296 if (rfkill_register(sc->rf_kill.rfkill)) {
1297 DPRINTF(sc, ATH_DBG_FATAL,
1298 "Unable to register rfkill\n");
1299 rfkill_free(sc->rf_kill.rfkill);
1300
1301 /* Deinitialize the device */
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001302 ath_cleanup(sc);
Sujith9c84b792008-10-29 10:17:13 +05301303 return -EIO;
1304 } else {
1305 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
1306 }
1307 }
1308
1309 return 0;
1310}
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301311#endif /* CONFIG_RFKILL */
1312
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001313void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001314{
1315 ath_detach(sc);
1316 free_irq(sc->irq, sc);
1317 ath_bus_cleanup(sc);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001318 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001319 ieee80211_free_hw(sc->hw);
1320}
1321
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001322void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301323{
1324 struct ieee80211_hw *hw = sc->hw;
Sujith9c84b792008-10-29 10:17:13 +05301325 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301326
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301327 ath9k_ps_wakeup(sc);
1328
Sujith04bd4632008-11-28 22:18:05 +05301329 DPRINTF(sc, ATH_DBG_CONFIG, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301330
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05301331#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301332 ath_deinit_rfkill(sc);
1333#endif
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301334 ath_deinit_leds(sc);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001335 cancel_work_sync(&sc->chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001336 cancel_delayed_work_sync(&sc->wiphy_work);
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301337
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001338 for (i = 0; i < sc->num_sec_wiphy; i++) {
1339 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1340 if (aphy == NULL)
1341 continue;
1342 sc->sec_wiphy[i] = NULL;
1343 ieee80211_unregister_hw(aphy->hw);
1344 ieee80211_free_hw(aphy->hw);
1345 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301346 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301347 ath_rx_cleanup(sc);
1348 ath_tx_cleanup(sc);
1349
Sujith9c84b792008-10-29 10:17:13 +05301350 tasklet_kill(&sc->intr_tq);
1351 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301352
Sujith9c84b792008-10-29 10:17:13 +05301353 if (!(sc->sc_flags & SC_OP_INVALID))
1354 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301355
Sujith9c84b792008-10-29 10:17:13 +05301356 /* cleanup tx queues */
1357 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1358 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301359 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301360
1361 ath9k_hw_detach(sc->sc_ah);
Sujith826d2682008-11-28 22:20:23 +05301362 ath9k_exit_debug(sc);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301363 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301364}
1365
Bob Copelande3bb2492009-03-30 22:30:30 -04001366static int ath9k_reg_notifier(struct wiphy *wiphy,
1367 struct regulatory_request *request)
1368{
1369 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1370 struct ath_wiphy *aphy = hw->priv;
1371 struct ath_softc *sc = aphy->sc;
1372 struct ath_regulatory *reg = &sc->sc_ah->regulatory;
1373
1374 return ath_reg_notifier_apply(wiphy, request, reg);
1375}
1376
Sujithff37e332008-11-24 12:07:55 +05301377static int ath_init(u16 devid, struct ath_softc *sc)
1378{
Sujithcbe61d82009-02-09 13:27:12 +05301379 struct ath_hw *ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301380 int status;
1381 int error = 0, i;
1382 int csz = 0;
1383
1384 /* XXX: hardware will not be ready until ath_open() being called */
1385 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301386
Sujith826d2682008-11-28 22:20:23 +05301387 if (ath9k_init_debug(sc) < 0)
1388 printk(KERN_ERR "Unable to create debugfs files\n");
Sujithff37e332008-11-24 12:07:55 +05301389
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001390 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301391 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001392 spin_lock_init(&sc->sc_serial_rw);
Sujithaa33de02008-12-18 11:40:16 +05301393 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301394 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301395 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301396 (unsigned long)sc);
1397
1398 /*
1399 * Cache line size is used to size and align various
1400 * structures used to communicate with the hardware.
1401 */
Gabor Juhos88d15702009-01-14 20:17:04 +01001402 ath_read_cachesize(sc, &csz);
Sujithff37e332008-11-24 12:07:55 +05301403 /* XXX assert csz is non-zero */
Sujith17d79042009-02-09 13:27:03 +05301404 sc->cachelsz = csz << 2; /* convert to bytes */
Sujithff37e332008-11-24 12:07:55 +05301405
Sujithcbe61d82009-02-09 13:27:12 +05301406 ah = ath9k_hw_attach(devid, sc, &status);
Sujithff37e332008-11-24 12:07:55 +05301407 if (ah == NULL) {
1408 DPRINTF(sc, ATH_DBG_FATAL,
Gabor Juhos295834f2008-12-29 21:07:42 +01001409 "Unable to attach hardware; HAL status %d\n", status);
Sujithff37e332008-11-24 12:07:55 +05301410 error = -ENXIO;
1411 goto bad;
1412 }
1413 sc->sc_ah = ah;
1414
1415 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301416 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301417 if (sc->keymax > ATH_KEYMAX) {
Sujithd8baa932009-03-30 15:28:25 +05301418 DPRINTF(sc, ATH_DBG_ANY,
Sujith04bd4632008-11-28 22:18:05 +05301419 "Warning, using only %u entries in %u key cache\n",
Sujith17d79042009-02-09 13:27:03 +05301420 ATH_KEYMAX, sc->keymax);
1421 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301422 }
1423
1424 /*
1425 * Reset the key cache since some parts do not
1426 * reset the contents on initial power up.
1427 */
Sujith17d79042009-02-09 13:27:03 +05301428 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301429 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301430
Bob Copelande3bb2492009-03-30 22:30:30 -04001431 if (ath_regd_init(&sc->sc_ah->regulatory, sc->hw->wiphy,
1432 ath9k_reg_notifier))
Sujithff37e332008-11-24 12:07:55 +05301433 goto bad;
1434
1435 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301436 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001437
Sujithff37e332008-11-24 12:07:55 +05301438 /* Setup rate tables */
1439
1440 ath_rate_attach(sc);
1441 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1442 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1443
1444 /*
1445 * Allocate hardware transmit queues: one queue for
1446 * beacon frames and one data queue for each QoS
1447 * priority. Note that the hal handles reseting
1448 * these queues at the needed time.
1449 */
Sujithb77f4832008-12-07 21:44:03 +05301450 sc->beacon.beaconq = ath_beaconq_setup(ah);
1451 if (sc->beacon.beaconq == -1) {
Sujithff37e332008-11-24 12:07:55 +05301452 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301453 "Unable to setup a beacon xmit queue\n");
Sujithff37e332008-11-24 12:07:55 +05301454 error = -EIO;
1455 goto bad2;
1456 }
Sujithb77f4832008-12-07 21:44:03 +05301457 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1458 if (sc->beacon.cabq == NULL) {
Sujithff37e332008-11-24 12:07:55 +05301459 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301460 "Unable to setup CAB xmit queue\n");
Sujithff37e332008-11-24 12:07:55 +05301461 error = -EIO;
1462 goto bad2;
1463 }
1464
Sujith17d79042009-02-09 13:27:03 +05301465 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301466 ath_cabq_update(sc);
1467
Sujithb77f4832008-12-07 21:44:03 +05301468 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1469 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301470
1471 /* Setup data queues */
1472 /* NB: ensure BK queue is the lowest priority h/w queue */
1473 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
1474 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301475 "Unable to setup xmit queue for BK traffic\n");
Sujithff37e332008-11-24 12:07:55 +05301476 error = -EIO;
1477 goto bad2;
1478 }
1479
1480 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
1481 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301482 "Unable to setup xmit queue for BE traffic\n");
Sujithff37e332008-11-24 12:07:55 +05301483 error = -EIO;
1484 goto bad2;
1485 }
1486 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
1487 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301488 "Unable to setup xmit queue for VI traffic\n");
Sujithff37e332008-11-24 12:07:55 +05301489 error = -EIO;
1490 goto bad2;
1491 }
1492 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
1493 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05301494 "Unable to setup xmit queue for VO traffic\n");
Sujithff37e332008-11-24 12:07:55 +05301495 error = -EIO;
1496 goto bad2;
1497 }
1498
1499 /* Initializes the noise floor to a reasonable default value.
1500 * Later on this will be updated during ANI processing. */
1501
Sujith17d79042009-02-09 13:27:03 +05301502 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1503 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301504
1505 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1506 ATH9K_CIPHER_TKIP, NULL)) {
1507 /*
1508 * Whether we should enable h/w TKIP MIC.
1509 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1510 * report WMM capable, so it's always safe to turn on
1511 * TKIP MIC in this case.
1512 */
1513 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1514 0, 1, NULL);
1515 }
1516
1517 /*
1518 * Check whether the separate key cache entries
1519 * are required to handle both tx+rx MIC keys.
1520 * With split mic keys the number of stations is limited
1521 * to 27 otherwise 59.
1522 */
1523 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1524 ATH9K_CIPHER_TKIP, NULL)
1525 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1526 ATH9K_CIPHER_MIC, NULL)
1527 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1528 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301529 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301530
1531 /* turn on mcast key search if possible */
1532 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1533 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1534 1, NULL);
1535
Sujith17d79042009-02-09 13:27:03 +05301536 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301537
1538 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301539 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301540 sc->sc_flags |= SC_OP_TXAGGR;
1541 sc->sc_flags |= SC_OP_RXAGGR;
1542 }
1543
Sujith2660b812009-02-09 13:27:26 +05301544 sc->tx_chainmask = ah->caps.tx_chainmask;
1545 sc->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301546
1547 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301548 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301549
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001550 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Sujithba52da52009-02-09 13:27:10 +05301551 memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301552
Sujithb77f4832008-12-07 21:44:03 +05301553 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301554
1555 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001556 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001557 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001558 sc->beacon.bslot_aphy[i] = NULL;
1559 }
Sujithff37e332008-11-24 12:07:55 +05301560
Sujithff37e332008-11-24 12:07:55 +05301561 /* setup channels and rates */
1562
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001563 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301564 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1565 sc->rates[IEEE80211_BAND_2GHZ];
1566 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001567 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1568 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301569
Sujith2660b812009-02-09 13:27:26 +05301570 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001571 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301572 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1573 sc->rates[IEEE80211_BAND_5GHZ];
1574 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001575 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1576 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301577 }
1578
Sujith2660b812009-02-09 13:27:26 +05301579 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301580 ath9k_hw_btcoex_enable(sc->sc_ah);
1581
Sujithff37e332008-11-24 12:07:55 +05301582 return 0;
1583bad2:
1584 /* cleanup tx queues */
1585 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1586 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301587 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301588bad:
1589 if (ah)
1590 ath9k_hw_detach(ah);
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301591 ath9k_exit_debug(sc);
Sujithff37e332008-11-24 12:07:55 +05301592
1593 return error;
1594}
1595
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001596void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301597{
Sujith9c84b792008-10-29 10:17:13 +05301598 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1599 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1600 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301601 IEEE80211_HW_AMPDU_AGGREGATION |
1602 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301603 IEEE80211_HW_PS_NULLFUNC_STACK |
1604 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301605
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001606 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001607 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1608
Sujith9c84b792008-10-29 10:17:13 +05301609 hw->wiphy->interface_modes =
1610 BIT(NL80211_IFTYPE_AP) |
1611 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001612 BIT(NL80211_IFTYPE_ADHOC) |
1613 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301614
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301615 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301616 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301617 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001618 hw->max_listen_interval = 10;
Sujithe63835b2008-11-18 09:07:53 +05301619 hw->max_rate_tries = ATH_11N_TXMAXTRY;
Sujith528f0c62008-10-29 10:14:26 +05301620 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301621 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301622
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301623 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301624
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001625 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1626 &sc->sbands[IEEE80211_BAND_2GHZ];
1627 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1628 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1629 &sc->sbands[IEEE80211_BAND_5GHZ];
1630}
1631
1632int ath_attach(u16 devid, struct ath_softc *sc)
1633{
1634 struct ieee80211_hw *hw = sc->hw;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001635 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001636 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001637
1638 DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
1639
1640 error = ath_init(devid, sc);
1641 if (error != 0)
1642 return error;
1643
Bob Copelandc02cf372009-03-30 22:30:28 -04001644 reg = &sc->sc_ah->regulatory;
1645
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001646 /* get mac address from hardware and set in mac80211 */
1647
1648 SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr);
1649
1650 ath_set_hw_capab(sc, hw);
1651
Sujith2660b812009-02-09 13:27:26 +05301652 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301653 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Sujith2660b812009-02-09 13:27:26 +05301654 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301655 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301656 }
1657
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301658 /* initialize tx/rx engine */
1659 error = ath_tx_init(sc, ATH_TXBUF);
1660 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301661 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301662
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301663 error = ath_rx_init(sc, ATH_RXBUF);
1664 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301665 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301666
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05301667#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301668 /* Initialze h/w Rfkill */
Sujith2660b812009-02-09 13:27:26 +05301669 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301670 INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll);
1671
1672 /* Initialize s/w rfkill */
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301673 error = ath_init_sw_rfkill(sc);
1674 if (error)
1675 goto error_attach;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301676#endif
1677
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001678 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001679 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1680 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001681
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301682 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301683
Bob Copeland3a702e42009-03-30 22:30:29 -04001684 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001685 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001686 if (error)
1687 goto error_attach;
1688 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001689
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301690 /* Initialize LED control */
1691 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301692
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001693
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301694 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301695
1696error_attach:
1697 /* cleanup tx queues */
1698 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1699 if (ATH_TXQ_SETUP(sc, i))
1700 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1701
1702 ath9k_hw_detach(sc->sc_ah);
1703 ath9k_exit_debug(sc);
1704
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301705 return error;
1706}
1707
Sujithff37e332008-11-24 12:07:55 +05301708int ath_reset(struct ath_softc *sc, bool retry_tx)
1709{
Sujithcbe61d82009-02-09 13:27:12 +05301710 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001711 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001712 int r;
Sujithff37e332008-11-24 12:07:55 +05301713
1714 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301715 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301716 ath_stoprecv(sc);
1717 ath_flushrecv(sc);
1718
1719 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301720 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001721 if (r)
Sujithff37e332008-11-24 12:07:55 +05301722 DPRINTF(sc, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001723 "Unable to reset hardware; reset status %u\n", r);
Sujithff37e332008-11-24 12:07:55 +05301724 spin_unlock_bh(&sc->sc_resetlock);
1725
1726 if (ath_startrecv(sc) != 0)
Sujith04bd4632008-11-28 22:18:05 +05301727 DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301728
1729 /*
1730 * We may be doing a reset in response to a request
1731 * that changes the channel so update any state that
1732 * might change as a result.
1733 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001734 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301735
1736 ath_update_txpow(sc);
1737
1738 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001739 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301740
Sujith17d79042009-02-09 13:27:03 +05301741 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301742
1743 if (retry_tx) {
1744 int i;
1745 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1746 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301747 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1748 ath_txq_schedule(sc, &sc->tx.txq[i]);
1749 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301750 }
1751 }
1752 }
1753
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001754 return r;
Sujithff37e332008-11-24 12:07:55 +05301755}
1756
1757/*
1758 * This function will allocate both the DMA descriptor structure, and the
1759 * buffers it contains. These are used to contain the descriptors used
1760 * by the system.
1761*/
1762int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1763 struct list_head *head, const char *name,
1764 int nbuf, int ndesc)
1765{
1766#define DS2PHYS(_dd, _ds) \
1767 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1768#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1769#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1770
1771 struct ath_desc *ds;
1772 struct ath_buf *bf;
1773 int i, bsize, error;
1774
Sujith04bd4632008-11-28 22:18:05 +05301775 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
1776 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05301777
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05301778 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05301779 /* ath_desc must be a multiple of DWORDs */
1780 if ((sizeof(struct ath_desc) % 4) != 0) {
Sujith04bd4632008-11-28 22:18:05 +05301781 DPRINTF(sc, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
Sujithff37e332008-11-24 12:07:55 +05301782 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1783 error = -ENOMEM;
1784 goto fail;
1785 }
1786
Sujithff37e332008-11-24 12:07:55 +05301787 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1788
1789 /*
1790 * Need additional DMA memory because we can't use
1791 * descriptors that cross the 4K page boundary. Assume
1792 * one skipped descriptor per 4K page.
1793 */
Sujith2660b812009-02-09 13:27:26 +05301794 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05301795 u32 ndesc_skipped =
1796 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1797 u32 dma_len;
1798
1799 while (ndesc_skipped) {
1800 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1801 dd->dd_desc_len += dma_len;
1802
1803 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
1804 };
1805 }
1806
1807 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001808 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301809 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301810 if (dd->dd_desc == NULL) {
1811 error = -ENOMEM;
1812 goto fail;
1813 }
1814 ds = dd->dd_desc;
Sujith04bd4632008-11-28 22:18:05 +05301815 DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Sujithae459af2009-03-30 15:28:40 +05301816 name, ds, (u32) dd->dd_desc_len,
Sujithff37e332008-11-24 12:07:55 +05301817 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1818
1819 /* allocate buffers */
1820 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301821 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301822 if (bf == NULL) {
1823 error = -ENOMEM;
1824 goto fail2;
1825 }
Sujithff37e332008-11-24 12:07:55 +05301826 dd->dd_bufptr = bf;
1827
Sujithff37e332008-11-24 12:07:55 +05301828 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
1829 bf->bf_desc = ds;
1830 bf->bf_daddr = DS2PHYS(dd, ds);
1831
Sujith2660b812009-02-09 13:27:26 +05301832 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05301833 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1834 /*
1835 * Skip descriptor addresses which can cause 4KB
1836 * boundary crossing (addr + length) with a 32 dword
1837 * descriptor fetch.
1838 */
1839 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
1840 ASSERT((caddr_t) bf->bf_desc <
1841 ((caddr_t) dd->dd_desc +
1842 dd->dd_desc_len));
1843
1844 ds += ndesc;
1845 bf->bf_desc = ds;
1846 bf->bf_daddr = DS2PHYS(dd, ds);
1847 }
1848 }
1849 list_add_tail(&bf->list, head);
1850 }
1851 return 0;
1852fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01001853 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1854 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05301855fail:
1856 memset(dd, 0, sizeof(*dd));
1857 return error;
1858#undef ATH_DESC_4KB_BOUND_CHECK
1859#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1860#undef DS2PHYS
1861}
1862
1863void ath_descdma_cleanup(struct ath_softc *sc,
1864 struct ath_descdma *dd,
1865 struct list_head *head)
1866{
Gabor Juhos7da3c552009-01-14 20:17:03 +01001867 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1868 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05301869
1870 INIT_LIST_HEAD(head);
1871 kfree(dd->dd_bufptr);
1872 memset(dd, 0, sizeof(*dd));
1873}
1874
1875int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
1876{
1877 int qnum;
1878
1879 switch (queue) {
1880 case 0:
Sujithb77f4832008-12-07 21:44:03 +05301881 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301882 break;
1883 case 1:
Sujithb77f4832008-12-07 21:44:03 +05301884 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301885 break;
1886 case 2:
Sujithb77f4832008-12-07 21:44:03 +05301887 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301888 break;
1889 case 3:
Sujithb77f4832008-12-07 21:44:03 +05301890 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301891 break;
1892 default:
Sujithb77f4832008-12-07 21:44:03 +05301893 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301894 break;
1895 }
1896
1897 return qnum;
1898}
1899
1900int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1901{
1902 int qnum;
1903
1904 switch (queue) {
1905 case ATH9K_WME_AC_VO:
1906 qnum = 0;
1907 break;
1908 case ATH9K_WME_AC_VI:
1909 qnum = 1;
1910 break;
1911 case ATH9K_WME_AC_BE:
1912 qnum = 2;
1913 break;
1914 case ATH9K_WME_AC_BK:
1915 qnum = 3;
1916 break;
1917 default:
1918 qnum = -1;
1919 break;
1920 }
1921
1922 return qnum;
1923}
1924
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001925/* XXX: Remove me once we don't depend on ath9k_channel for all
1926 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001927void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1928 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001929{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001930 struct ieee80211_channel *chan = hw->conf.channel;
1931 struct ieee80211_conf *conf = &hw->conf;
1932
1933 ichan->channel = chan->center_freq;
1934 ichan->chan = chan;
1935
1936 if (chan->band == IEEE80211_BAND_2GHZ) {
1937 ichan->chanmode = CHANNEL_G;
1938 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
1939 } else {
1940 ichan->chanmode = CHANNEL_A;
1941 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1942 }
1943
1944 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
1945
1946 if (conf_is_ht(conf)) {
1947 if (conf_is_ht40(conf))
1948 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
1949
1950 ichan->chanmode = ath_get_extchanmode(sc, chan,
1951 conf->channel_type);
1952 }
1953}
1954
Sujithff37e332008-11-24 12:07:55 +05301955/**********************/
1956/* mac80211 callbacks */
1957/**********************/
1958
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001959static int ath9k_start(struct ieee80211_hw *hw)
1960{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001961 struct ath_wiphy *aphy = hw->priv;
1962 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001963 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301964 struct ath9k_channel *init_channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001965 int r, pos;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001966
Sujith04bd4632008-11-28 22:18:05 +05301967 DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with "
1968 "initial channel: %d MHz\n", curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969
Sujith141b38b2009-02-04 08:10:07 +05301970 mutex_lock(&sc->mutex);
1971
Jouni Malinen9580a222009-03-03 19:23:33 +02001972 if (ath9k_wiphy_started(sc)) {
1973 if (sc->chan_idx == curchan->hw_value) {
1974 /*
1975 * Already on the operational channel, the new wiphy
1976 * can be marked active.
1977 */
1978 aphy->state = ATH_WIPHY_ACTIVE;
1979 ieee80211_wake_queues(hw);
1980 } else {
1981 /*
1982 * Another wiphy is on another channel, start the new
1983 * wiphy in paused state.
1984 */
1985 aphy->state = ATH_WIPHY_PAUSED;
1986 ieee80211_stop_queues(hw);
1987 }
1988 mutex_unlock(&sc->mutex);
1989 return 0;
1990 }
1991 aphy->state = ATH_WIPHY_ACTIVE;
1992
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 /* setup initial channel */
1994
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001995 pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001996
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001997 sc->chan_idx = pos;
Sujith2660b812009-02-09 13:27:26 +05301998 init_channel = &sc->sc_ah->channels[pos];
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001999 ath9k_update_ichannel(sc, hw, init_channel);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002000
Sujithff37e332008-11-24 12:07:55 +05302001 /* Reset SERDES registers */
2002 ath9k_hw_configpcipowersave(sc->sc_ah, 0);
2003
2004 /*
2005 * The basic interface to setting the hardware in a good
2006 * state is ``reset''. On return the hardware is known to
2007 * be powered up and with interrupts disabled. This must
2008 * be followed by initialization of the appropriate bits
2009 * and then setup of the interrupt mask.
2010 */
2011 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002012 r = ath9k_hw_reset(sc->sc_ah, init_channel, false);
2013 if (r) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002014 DPRINTF(sc, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002015 "Unable to reset hardware; reset status %u "
2016 "(freq %u MHz)\n", r,
2017 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05302018 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05302019 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002020 }
Sujithff37e332008-11-24 12:07:55 +05302021 spin_unlock_bh(&sc->sc_resetlock);
2022
2023 /*
2024 * This is needed only to setup initial state
2025 * but it's best done after a reset.
2026 */
2027 ath_update_txpow(sc);
2028
2029 /*
2030 * Setup the hardware after reset:
2031 * The receive engine is set going.
2032 * Frame transmit is handled entirely
2033 * in the frame output path; there's nothing to do
2034 * here except setup the interrupt mask.
2035 */
2036 if (ath_startrecv(sc) != 0) {
Sujith1ffb0612009-03-30 15:28:46 +05302037 DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05302038 r = -EIO;
2039 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05302040 }
2041
2042 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05302043 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05302044 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
2045 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
2046
Sujith2660b812009-02-09 13:27:26 +05302047 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05302048 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05302049
Sujith2660b812009-02-09 13:27:26 +05302050 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302051 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302052
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002053 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302054
2055 sc->sc_flags &= ~SC_OP_INVALID;
2056
2057 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302058 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
2059 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302060
Jouni Malinenbce048d2009-03-03 19:23:28 +02002061 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002062
Senthil Balasubramaniane97275c2008-11-13 18:00:02 +05302063#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002064 r = ath_start_rfkill_poll(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05302065#endif
Sujith141b38b2009-02-04 08:10:07 +05302066
2067mutex_unlock:
2068 mutex_unlock(&sc->mutex);
2069
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002070 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002071}
2072
2073static int ath9k_tx(struct ieee80211_hw *hw,
2074 struct sk_buff *skb)
2075{
Jouni Malinen147583c2008-08-11 14:01:50 +03002076 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002077 struct ath_wiphy *aphy = hw->priv;
2078 struct ath_softc *sc = aphy->sc;
Sujith528f0c62008-10-29 10:14:26 +05302079 struct ath_tx_control txctl;
2080 int hdrlen, padsize;
2081
Jouni Malinen8089cc42009-03-03 19:23:38 +02002082 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Jouni Malinenee166a02009-03-03 19:23:36 +02002083 printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
2084 "%d\n", wiphy_name(hw->wiphy), aphy->state);
2085 goto exit;
2086 }
2087
Sujith528f0c62008-10-29 10:14:26 +05302088 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002089
2090 /*
2091 * As a temporary workaround, assign seq# here; this will likely need
2092 * to be cleaned up to work better with Beacon transmission and virtual
2093 * BSSes.
2094 */
2095 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2096 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2097 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302098 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002099 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302100 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002101 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002102
2103 /* Add the padding after the header if this is not already done */
2104 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2105 if (hdrlen & 3) {
2106 padsize = hdrlen % 4;
2107 if (skb_headroom(skb) < padsize)
2108 return -1;
2109 skb_push(skb, padsize);
2110 memmove(skb->data, skb->data + padsize, hdrlen);
2111 }
2112
Sujith528f0c62008-10-29 10:14:26 +05302113 /* Check if a tx queue is available */
2114
2115 txctl.txq = ath_test_get_txq(sc, skb);
2116 if (!txctl.txq)
2117 goto exit;
2118
Sujith04bd4632008-11-28 22:18:05 +05302119 DPRINTF(sc, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002120
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002121 if (ath_tx_start(hw, skb, &txctl) != 0) {
Sujith04bd4632008-11-28 22:18:05 +05302122 DPRINTF(sc, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302123 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002124 }
2125
2126 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302127exit:
2128 dev_kfree_skb_any(skb);
2129 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002130}
2131
2132static void ath9k_stop(struct ieee80211_hw *hw)
2133{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002134 struct ath_wiphy *aphy = hw->priv;
2135 struct ath_softc *sc = aphy->sc;
Sujith9c84b792008-10-29 10:17:13 +05302136
Jouni Malinen9580a222009-03-03 19:23:33 +02002137 aphy->state = ATH_WIPHY_INACTIVE;
2138
Sujith9c84b792008-10-29 10:17:13 +05302139 if (sc->sc_flags & SC_OP_INVALID) {
Sujith04bd4632008-11-28 22:18:05 +05302140 DPRINTF(sc, ATH_DBG_ANY, "Device not present\n");
Sujith9c84b792008-10-29 10:17:13 +05302141 return;
2142 }
2143
Sujith141b38b2009-02-04 08:10:07 +05302144 mutex_lock(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05302145
Jouni Malinenbce048d2009-03-03 19:23:28 +02002146 ieee80211_stop_queues(hw);
Sujithff37e332008-11-24 12:07:55 +05302147
Jouni Malinen9580a222009-03-03 19:23:33 +02002148 if (ath9k_wiphy_started(sc)) {
2149 mutex_unlock(&sc->mutex);
2150 return; /* another wiphy still in use */
2151 }
2152
Sujithff37e332008-11-24 12:07:55 +05302153 /* make sure h/w will not generate any interrupt
2154 * before setting the invalid flag. */
2155 ath9k_hw_set_interrupts(sc->sc_ah, 0);
2156
2157 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302158 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302159 ath_stoprecv(sc);
2160 ath9k_hw_phy_disable(sc->sc_ah);
2161 } else
Sujithb77f4832008-12-07 21:44:03 +05302162 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302163
2164#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
Sujith2660b812009-02-09 13:27:26 +05302165 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
Sujithff37e332008-11-24 12:07:55 +05302166 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
2167#endif
2168 /* disable HAL and put h/w to sleep */
2169 ath9k_hw_disable(sc->sc_ah);
2170 ath9k_hw_configpcipowersave(sc->sc_ah, 1);
2171
2172 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002173
Sujith141b38b2009-02-04 08:10:07 +05302174 mutex_unlock(&sc->mutex);
2175
Sujith04bd4632008-11-28 22:18:05 +05302176 DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002177}
2178
2179static int ath9k_add_interface(struct ieee80211_hw *hw,
2180 struct ieee80211_if_init_conf *conf)
2181{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002182 struct ath_wiphy *aphy = hw->priv;
2183 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302184 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002185 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002186 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002187
Sujith141b38b2009-02-04 08:10:07 +05302188 mutex_lock(&sc->mutex);
2189
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002190 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2191 sc->nvifs > 0) {
2192 ret = -ENOBUFS;
2193 goto out;
2194 }
2195
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002196 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002197 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002198 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002199 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002200 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002201 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002202 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002203 if (sc->nbcnvifs >= ATH_BCBUF) {
2204 ret = -ENOBUFS;
2205 goto out;
2206 }
Pat Erley9cb54122009-03-20 22:59:59 -04002207 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002208 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002209 default:
2210 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302211 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002212 ret = -EOPNOTSUPP;
2213 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002214 }
2215
Sujith17d79042009-02-09 13:27:03 +05302216 DPRINTF(sc, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217
Sujith17d79042009-02-09 13:27:03 +05302218 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302219 avp->av_opmode = ic_opmode;
2220 avp->av_bslot = -1;
2221
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002222 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002223
2224 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2225 ath9k_set_bssid_mask(hw);
2226
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002227 if (sc->nvifs > 1)
2228 goto out; /* skip global settings for secondary vif */
2229
Sujithb238e902009-03-03 10:16:56 +05302230 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302231 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302232 sc->sc_flags |= SC_OP_TSF_RESET;
2233 }
Sujith5640b082008-10-29 10:16:06 +05302234
Sujith5640b082008-10-29 10:16:06 +05302235 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302236 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302237
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302238 /*
2239 * Enable MIB interrupts when there are hardware phy counters.
2240 * Note we only do this (at the moment) for station mode.
2241 */
Sujith4af9cf42009-02-12 10:06:47 +05302242 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002243 (conf->type == NL80211_IFTYPE_ADHOC) ||
2244 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith4af9cf42009-02-12 10:06:47 +05302245 if (ath9k_hw_phycounters(sc->sc_ah))
2246 sc->imask |= ATH9K_INT_MIB;
2247 sc->imask |= ATH9K_INT_TSFOOR;
2248 }
2249
Sujith17d79042009-02-09 13:27:03 +05302250 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302251
Sujith415f7382009-04-13 21:56:46 +05302252 if (conf->type == NL80211_IFTYPE_AP)
2253 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002254
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002255out:
Sujith141b38b2009-02-04 08:10:07 +05302256 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002257 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002258}
2259
2260static void ath9k_remove_interface(struct ieee80211_hw *hw,
2261 struct ieee80211_if_init_conf *conf)
2262{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002263 struct ath_wiphy *aphy = hw->priv;
2264 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302265 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002266 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267
Sujith04bd4632008-11-28 22:18:05 +05302268 DPRINTF(sc, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002269
Sujith141b38b2009-02-04 08:10:07 +05302270 mutex_lock(&sc->mutex);
2271
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002272 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302273 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002274
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002275 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002276 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2277 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2278 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302279 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002280 ath_beacon_return(sc, avp);
2281 }
2282
Sujith672840a2008-08-11 14:05:08 +05302283 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002284
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002285 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2286 if (sc->beacon.bslot[i] == conf->vif) {
2287 printk(KERN_DEBUG "%s: vif had allocated beacon "
2288 "slot\n", __func__);
2289 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002290 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002291 }
2292 }
2293
Sujith17d79042009-02-09 13:27:03 +05302294 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302295
2296 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002297}
2298
Johannes Berge8975582008-10-09 12:18:51 +02002299static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002300{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002301 struct ath_wiphy *aphy = hw->priv;
2302 struct ath_softc *sc = aphy->sc;
Johannes Berge8975582008-10-09 12:18:51 +02002303 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302304 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002305
Sujithaa33de02008-12-18 11:40:16 +05302306 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302307
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302308 if (changed & IEEE80211_CONF_CHANGE_PS) {
2309 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302310 if (!(ah->caps.hw_caps &
2311 ATH9K_HW_CAP_AUTOSLEEP)) {
2312 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2313 sc->imask |= ATH9K_INT_TIM_TIMER;
2314 ath9k_hw_set_interrupts(sc->sc_ah,
2315 sc->imask);
2316 }
2317 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302318 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302319 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
2320 } else {
2321 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302322 if (!(ah->caps.hw_caps &
2323 ATH9K_HW_CAP_AUTOSLEEP)) {
2324 ath9k_hw_setrxabort(sc->sc_ah, 0);
2325 sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
2326 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2327 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2328 ath9k_hw_set_interrupts(sc->sc_ah,
2329 sc->imask);
2330 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302331 }
2332 }
2333 }
2334
Johannes Berg47979382009-01-07 10:13:27 +01002335 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302336 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002337 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002338
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002339 aphy->chan_idx = pos;
2340 aphy->chan_is_ht = conf_is_ht(conf);
2341
Jouni Malinen8089cc42009-03-03 19:23:38 +02002342 if (aphy->state == ATH_WIPHY_SCAN ||
2343 aphy->state == ATH_WIPHY_ACTIVE)
2344 ath9k_wiphy_pause_all_forced(sc, aphy);
2345 else {
2346 /*
2347 * Do not change operational channel based on a paused
2348 * wiphy changes.
2349 */
2350 goto skip_chan_change;
2351 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002352
Sujith04bd4632008-11-28 22:18:05 +05302353 DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
2354 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002355
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002356 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002357 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302358
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002359 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302360
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002361 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Sujith04bd4632008-11-28 22:18:05 +05302362 DPRINTF(sc, ATH_DBG_FATAL, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302363 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302364 return -EINVAL;
2365 }
Sujith094d05d2008-12-12 11:57:43 +05302366 }
Sujith86b89ee2008-08-07 10:54:57 +05302367
Jouni Malinen8089cc42009-03-03 19:23:38 +02002368skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002369 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302370 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002371
Sujithb238e902009-03-03 10:16:56 +05302372 /*
2373 * The HW TSF has to be reset when the beacon interval changes.
2374 * We set the flag here, and ath_beacon_config_ap() would take this
2375 * into account when it gets called through the subsequent
2376 * config_interface() call - with IFCC_BEACON in the changed field.
2377 */
2378
2379 if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
2380 sc->sc_flags |= SC_OP_TSF_RESET;
2381
Sujithaa33de02008-12-18 11:40:16 +05302382 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302383
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002384 return 0;
2385}
2386
2387static int ath9k_config_interface(struct ieee80211_hw *hw,
2388 struct ieee80211_vif *vif,
2389 struct ieee80211_if_conf *conf)
2390{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002391 struct ath_wiphy *aphy = hw->priv;
2392 struct ath_softc *sc = aphy->sc;
Sujithcbe61d82009-02-09 13:27:12 +05302393 struct ath_hw *ah = sc->sc_ah;
Sujith17d79042009-02-09 13:27:03 +05302394 struct ath_vif *avp = (void *)vif->drv_priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002395 u32 rfilt = 0;
2396 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002397
Sujith25549352009-03-03 10:16:57 +05302398 mutex_lock(&sc->mutex);
2399
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002400 /* TODO: Need to decide which hw opmode to use for multi-interface
2401 * cases */
Johannes Berg05c914f2008-09-11 00:01:58 +02002402 if (vif->type == NL80211_IFTYPE_AP &&
Sujith2660b812009-02-09 13:27:26 +05302403 ah->opmode != NL80211_IFTYPE_AP) {
2404 ah->opmode = NL80211_IFTYPE_STATION;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002405 ath9k_hw_setopmode(ah);
Sujithba52da52009-02-09 13:27:10 +05302406 memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
2407 sc->curaid = 0;
2408 ath9k_hw_write_associd(sc);
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002409 /* Request full reset to get hw opmode changed properly */
2410 sc->sc_flags |= SC_OP_FULL_RESET;
2411 }
2412
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002413 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
2414 !is_zero_ether_addr(conf->bssid)) {
2415 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002416 case NL80211_IFTYPE_STATION:
2417 case NL80211_IFTYPE_ADHOC:
Pat Erley9cb54122009-03-20 22:59:59 -04002418 case NL80211_IFTYPE_MESH_POINT:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002419 /* Set BSSID */
Sujith17d79042009-02-09 13:27:03 +05302420 memcpy(sc->curbssid, conf->bssid, ETH_ALEN);
Jouni Malinenf0ed85c2009-03-03 19:23:31 +02002421 memcpy(avp->bssid, conf->bssid, ETH_ALEN);
Sujith17d79042009-02-09 13:27:03 +05302422 sc->curaid = 0;
Sujithba52da52009-02-09 13:27:10 +05302423 ath9k_hw_write_associd(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002424
2425 /* Set aggregation protection mode parameters */
Sujith17d79042009-02-09 13:27:03 +05302426 sc->config.ath_aggr_prot = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002427
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002428 DPRINTF(sc, ATH_DBG_CONFIG,
Sujith04bd4632008-11-28 22:18:05 +05302429 "RX filter 0x%x bssid %pM aid 0x%x\n",
Sujith17d79042009-02-09 13:27:03 +05302430 rfilt, sc->curbssid, sc->curaid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002431
2432 /* need to reconfigure the beacon */
Sujith672840a2008-08-11 14:05:08 +05302433 sc->sc_flags &= ~SC_OP_BEACONS ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002434
2435 break;
2436 default:
2437 break;
2438 }
2439 }
2440
Sujith1f7d6cb2009-01-27 10:55:54 +05302441 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002442 (vif->type == NL80211_IFTYPE_AP) ||
2443 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1f7d6cb2009-01-27 10:55:54 +05302444 if ((conf->changed & IEEE80211_IFCC_BEACON) ||
2445 (conf->changed & IEEE80211_IFCC_BEACON_ENABLED &&
2446 conf->enable_beacon)) {
2447 /*
2448 * Allocate and setup the beacon frame.
2449 *
2450 * Stop any previous beacon DMA. This may be
2451 * necessary, for example, when an ibss merge
2452 * causes reconfiguration; we may be called
2453 * with beacon transmission active.
2454 */
2455 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002456
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002457 error = ath_beacon_alloc(aphy, vif);
Sujith25549352009-03-03 10:16:57 +05302458 if (error != 0) {
2459 mutex_unlock(&sc->mutex);
Sujith1f7d6cb2009-01-27 10:55:54 +05302460 return error;
Sujith25549352009-03-03 10:16:57 +05302461 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002462
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002463 ath_beacon_config(sc, vif);
Sujith1f7d6cb2009-01-27 10:55:54 +05302464 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002465 }
2466
2467 /* Check for WLAN_CAPABILITY_PRIVACY ? */
Colin McCabed97809d2008-12-01 13:38:55 -08002468 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002469 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2470 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2471 ath9k_hw_keysetmac(sc->sc_ah,
2472 (u16)i,
Sujith17d79042009-02-09 13:27:03 +05302473 sc->curbssid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002474 }
2475
2476 /* Only legacy IBSS for now */
Johannes Berg05c914f2008-09-11 00:01:58 +02002477 if (vif->type == NL80211_IFTYPE_ADHOC)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002478 ath_update_chainmask(sc, 0);
2479
Sujith25549352009-03-03 10:16:57 +05302480 mutex_unlock(&sc->mutex);
2481
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002482 return 0;
2483}
2484
2485#define SUPPORTED_FILTERS \
2486 (FIF_PROMISC_IN_BSS | \
2487 FIF_ALLMULTI | \
2488 FIF_CONTROL | \
2489 FIF_OTHER_BSS | \
2490 FIF_BCN_PRBRESP_PROMISC | \
2491 FIF_FCSFAIL)
2492
Sujith7dcfdcd2008-08-11 14:03:13 +05302493/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002494static void ath9k_configure_filter(struct ieee80211_hw *hw,
2495 unsigned int changed_flags,
2496 unsigned int *total_flags,
2497 int mc_count,
2498 struct dev_mc_list *mclist)
2499{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002500 struct ath_wiphy *aphy = hw->priv;
2501 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302502 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002503
2504 changed_flags &= SUPPORTED_FILTERS;
2505 *total_flags &= SUPPORTED_FILTERS;
2506
Sujithb77f4832008-12-07 21:44:03 +05302507 sc->rx.rxfilter = *total_flags;
Sujith7dcfdcd2008-08-11 14:03:13 +05302508 rfilt = ath_calcrxfilter(sc);
2509 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
2510
Sujithb77f4832008-12-07 21:44:03 +05302511 DPRINTF(sc, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", sc->rx.rxfilter);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002512}
2513
2514static void ath9k_sta_notify(struct ieee80211_hw *hw,
2515 struct ieee80211_vif *vif,
2516 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002517 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002518{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002519 struct ath_wiphy *aphy = hw->priv;
2520 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002521
2522 switch (cmd) {
2523 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302524 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002525 break;
2526 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302527 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002528 break;
2529 default:
2530 break;
2531 }
2532}
2533
Sujith141b38b2009-02-04 08:10:07 +05302534static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002535 const struct ieee80211_tx_queue_params *params)
2536{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002537 struct ath_wiphy *aphy = hw->priv;
2538 struct ath_softc *sc = aphy->sc;
Sujithea9880f2008-08-07 10:53:10 +05302539 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002540 int ret = 0, qnum;
2541
2542 if (queue >= WME_NUM_AC)
2543 return 0;
2544
Sujith141b38b2009-02-04 08:10:07 +05302545 mutex_lock(&sc->mutex);
2546
Sujith1ffb0612009-03-30 15:28:46 +05302547 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2548
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002549 qi.tqi_aifs = params->aifs;
2550 qi.tqi_cwmin = params->cw_min;
2551 qi.tqi_cwmax = params->cw_max;
2552 qi.tqi_burstTime = params->txop;
2553 qnum = ath_get_hal_qnum(queue, sc);
2554
2555 DPRINTF(sc, ATH_DBG_CONFIG,
Sujith04bd4632008-11-28 22:18:05 +05302556 "Configure tx [queue/halq] [%d/%d], "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002557 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
Sujith04bd4632008-11-28 22:18:05 +05302558 queue, qnum, params->aifs, params->cw_min,
2559 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002560
2561 ret = ath_txq_update(sc, qnum, &qi);
2562 if (ret)
Sujith04bd4632008-11-28 22:18:05 +05302563 DPRINTF(sc, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002564
Sujith141b38b2009-02-04 08:10:07 +05302565 mutex_unlock(&sc->mutex);
2566
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002567 return ret;
2568}
2569
2570static int ath9k_set_key(struct ieee80211_hw *hw,
2571 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002572 struct ieee80211_vif *vif,
2573 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002574 struct ieee80211_key_conf *key)
2575{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002576 struct ath_wiphy *aphy = hw->priv;
2577 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002578 int ret = 0;
2579
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002580 if (modparam_nohwcrypt)
2581 return -ENOSPC;
2582
Sujith141b38b2009-02-04 08:10:07 +05302583 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302584 ath9k_ps_wakeup(sc);
Sujithd8baa932009-03-30 15:28:25 +05302585 DPRINTF(sc, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002586
2587 switch (cmd) {
2588 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002589 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002590 if (ret >= 0) {
2591 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002592 /* push IV and Michael MIC generation to stack */
2593 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302594 if (key->alg == ALG_TKIP)
2595 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002596 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2597 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002598 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002599 }
2600 break;
2601 case DISABLE_KEY:
2602 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002603 break;
2604 default:
2605 ret = -EINVAL;
2606 }
2607
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302608 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302609 mutex_unlock(&sc->mutex);
2610
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002611 return ret;
2612}
2613
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002614static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2615 struct ieee80211_vif *vif,
2616 struct ieee80211_bss_conf *bss_conf,
2617 u32 changed)
2618{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002619 struct ath_wiphy *aphy = hw->priv;
2620 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002621
Sujith141b38b2009-02-04 08:10:07 +05302622 mutex_lock(&sc->mutex);
2623
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002624 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Sujith04bd4632008-11-28 22:18:05 +05302625 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002626 bss_conf->use_short_preamble);
2627 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302628 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002629 else
Sujith672840a2008-08-11 14:05:08 +05302630 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002631 }
2632
2633 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Sujith04bd4632008-11-28 22:18:05 +05302634 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002635 bss_conf->use_cts_prot);
2636 if (bss_conf->use_cts_prot &&
2637 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302638 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002639 else
Sujith672840a2008-08-11 14:05:08 +05302640 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002641 }
2642
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643 if (changed & BSS_CHANGED_ASSOC) {
Sujith04bd4632008-11-28 22:18:05 +05302644 DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002645 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302646 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002647 }
Sujith141b38b2009-02-04 08:10:07 +05302648
2649 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002650}
2651
2652static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2653{
2654 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002655 struct ath_wiphy *aphy = hw->priv;
2656 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002657
Sujith141b38b2009-02-04 08:10:07 +05302658 mutex_lock(&sc->mutex);
2659 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2660 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661
2662 return tsf;
2663}
2664
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002665static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2666{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002667 struct ath_wiphy *aphy = hw->priv;
2668 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002669
Sujith141b38b2009-02-04 08:10:07 +05302670 mutex_lock(&sc->mutex);
2671 ath9k_hw_settsf64(sc->sc_ah, tsf);
2672 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002673}
2674
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002675static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2676{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002677 struct ath_wiphy *aphy = hw->priv;
2678 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002679
Sujith141b38b2009-02-04 08:10:07 +05302680 mutex_lock(&sc->mutex);
2681 ath9k_hw_reset_tsf(sc->sc_ah);
2682 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683}
2684
2685static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05302686 enum ieee80211_ampdu_mlme_action action,
2687 struct ieee80211_sta *sta,
2688 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002689{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002690 struct ath_wiphy *aphy = hw->priv;
2691 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002692 int ret = 0;
2693
2694 switch (action) {
2695 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05302696 if (!(sc->sc_flags & SC_OP_RXAGGR))
2697 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002698 break;
2699 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002700 break;
2701 case IEEE80211_AMPDU_TX_START:
Sujithb5aa9bf2008-10-29 10:13:31 +05302702 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002703 if (ret < 0)
2704 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302705 "Unable to start TX aggregation\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002706 else
Johannes Berg17741cd2008-09-11 00:02:02 +02002707 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002708 break;
2709 case IEEE80211_AMPDU_TX_STOP:
Sujithb5aa9bf2008-10-29 10:13:31 +05302710 ret = ath_tx_aggr_stop(sc, sta, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002711 if (ret < 0)
2712 DPRINTF(sc, ATH_DBG_FATAL,
Sujith04bd4632008-11-28 22:18:05 +05302713 "Unable to stop TX aggregation\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002714
Johannes Berg17741cd2008-09-11 00:02:02 +02002715 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002716 break;
Johannes Bergb1720232009-03-23 17:28:39 +01002717 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05302718 ath_tx_aggr_resume(sc, sta, tid);
2719 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002720 default:
Sujith04bd4632008-11-28 22:18:05 +05302721 DPRINTF(sc, ATH_DBG_FATAL, "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002722 }
2723
2724 return ret;
2725}
2726
Sujith0c98de62009-03-03 10:16:45 +05302727static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2728{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002729 struct ath_wiphy *aphy = hw->priv;
2730 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302731
Jouni Malinen8089cc42009-03-03 19:23:38 +02002732 if (ath9k_wiphy_scanning(sc)) {
2733 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
2734 "same time\n");
2735 /*
2736 * Do not allow the concurrent scanning state for now. This
2737 * could be improved with scanning control moved into ath9k.
2738 */
2739 return;
2740 }
2741
2742 aphy->state = ATH_WIPHY_SCAN;
2743 ath9k_wiphy_pause_all_forced(sc, aphy);
2744
Sujith0c98de62009-03-03 10:16:45 +05302745 mutex_lock(&sc->mutex);
2746 sc->sc_flags |= SC_OP_SCANNING;
2747 mutex_unlock(&sc->mutex);
2748}
2749
2750static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2751{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002752 struct ath_wiphy *aphy = hw->priv;
2753 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302754
2755 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002756 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05302757 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05302758 sc->sc_flags |= SC_OP_FULL_RESET;
Sujith0c98de62009-03-03 10:16:45 +05302759 mutex_unlock(&sc->mutex);
2760}
2761
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002762struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002763 .tx = ath9k_tx,
2764 .start = ath9k_start,
2765 .stop = ath9k_stop,
2766 .add_interface = ath9k_add_interface,
2767 .remove_interface = ath9k_remove_interface,
2768 .config = ath9k_config,
2769 .config_interface = ath9k_config_interface,
2770 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002771 .sta_notify = ath9k_sta_notify,
2772 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002773 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002774 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002775 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002776 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002777 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002778 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05302779 .sw_scan_start = ath9k_sw_scan_start,
2780 .sw_scan_complete = ath9k_sw_scan_complete,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002781};
2782
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002783static struct {
2784 u32 version;
2785 const char * name;
2786} ath_mac_bb_names[] = {
2787 { AR_SREV_VERSION_5416_PCI, "5416" },
2788 { AR_SREV_VERSION_5416_PCIE, "5418" },
2789 { AR_SREV_VERSION_9100, "9100" },
2790 { AR_SREV_VERSION_9160, "9160" },
2791 { AR_SREV_VERSION_9280, "9280" },
2792 { AR_SREV_VERSION_9285, "9285" }
2793};
2794
2795static struct {
2796 u16 version;
2797 const char * name;
2798} ath_rf_names[] = {
2799 { 0, "5133" },
2800 { AR_RAD5133_SREV_MAJOR, "5133" },
2801 { AR_RAD5122_SREV_MAJOR, "5122" },
2802 { AR_RAD2133_SREV_MAJOR, "2133" },
2803 { AR_RAD2122_SREV_MAJOR, "2122" }
2804};
2805
2806/*
2807 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2808 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002809const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002810ath_mac_bb_name(u32 mac_bb_version)
2811{
2812 int i;
2813
2814 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2815 if (ath_mac_bb_names[i].version == mac_bb_version) {
2816 return ath_mac_bb_names[i].name;
2817 }
2818 }
2819
2820 return "????";
2821}
2822
2823/*
2824 * Return the RF name. "????" is returned if the RF is unknown.
2825 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002826const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002827ath_rf_name(u16 rf_version)
2828{
2829 int i;
2830
2831 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2832 if (ath_rf_names[i].version == rf_version) {
2833 return ath_rf_names[i].name;
2834 }
2835 }
2836
2837 return "????";
2838}
2839
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002840static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002841{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302842 int error;
2843
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302844 /* Register rate control algorithm */
2845 error = ath_rate_control_register();
2846 if (error != 0) {
2847 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08002848 "ath9k: Unable to register rate control "
2849 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302850 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002851 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302852 }
2853
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002854 error = ath9k_debug_create_root();
2855 if (error) {
2856 printk(KERN_ERR
2857 "ath9k: Unable to create debugfs root: %d\n",
2858 error);
2859 goto err_rate_unregister;
2860 }
2861
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002862 error = ath_pci_init();
2863 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002864 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08002865 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002866 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002867 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002868 }
2869
Gabor Juhos09329d32009-01-14 20:17:07 +01002870 error = ath_ahb_init();
2871 if (error < 0) {
2872 error = -ENODEV;
2873 goto err_pci_exit;
2874 }
2875
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002876 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002877
Gabor Juhos09329d32009-01-14 20:17:07 +01002878 err_pci_exit:
2879 ath_pci_exit();
2880
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002881 err_remove_root:
2882 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002883 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302884 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002885 err_out:
2886 return error;
2887}
2888module_init(ath9k_init);
2889
2890static void __exit ath9k_exit(void)
2891{
Gabor Juhos09329d32009-01-14 20:17:07 +01002892 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002893 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002894 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002895 ath_rate_control_unregister();
Sujith04bd4632008-11-28 22:18:05 +05302896 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002897}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002898module_exit(ath9k_exit);