blob: 63e1f183b4702c5af47ae20af068ae245985d5a6 [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
Sujithcee075a2009-03-13 09:07:23 +05302 * Copyright (c) 2008-2009 Atheros Communications Inc.
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070017#include <linux/nl80211.h>
Sujith394cf0a2009-02-09 13:26:54 +053018#include "ath9k.h"
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -070019#include "btcoex.h"
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070020
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070021static char *dev_info = "ath9k";
22
23MODULE_AUTHOR("Atheros Communications");
24MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
25MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
26MODULE_LICENSE("Dual BSD/GPL");
27
Jouni Malinenb3bd89c2009-02-24 13:42:01 +020028static int modparam_nohwcrypt;
29module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
30MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
31
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080032/* We use the hw_value as an index into our private channel structure */
33
34#define CHAN2G(_freq, _idx) { \
35 .center_freq = (_freq), \
36 .hw_value = (_idx), \
Luis R. Rodriguezeeddfd92009-05-19 17:49:46 -040037 .max_power = 20, \
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080038}
39
40#define CHAN5G(_freq, _idx) { \
41 .band = IEEE80211_BAND_5GHZ, \
42 .center_freq = (_freq), \
43 .hw_value = (_idx), \
Luis R. Rodriguezeeddfd92009-05-19 17:49:46 -040044 .max_power = 20, \
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -080045}
46
47/* Some 2 GHz radios are actually tunable on 2312-2732
48 * on 5 MHz steps, we support the channels which we know
49 * we have calibration data for all cards though to make
50 * this static */
51static struct ieee80211_channel ath9k_2ghz_chantable[] = {
52 CHAN2G(2412, 0), /* Channel 1 */
53 CHAN2G(2417, 1), /* Channel 2 */
54 CHAN2G(2422, 2), /* Channel 3 */
55 CHAN2G(2427, 3), /* Channel 4 */
56 CHAN2G(2432, 4), /* Channel 5 */
57 CHAN2G(2437, 5), /* Channel 6 */
58 CHAN2G(2442, 6), /* Channel 7 */
59 CHAN2G(2447, 7), /* Channel 8 */
60 CHAN2G(2452, 8), /* Channel 9 */
61 CHAN2G(2457, 9), /* Channel 10 */
62 CHAN2G(2462, 10), /* Channel 11 */
63 CHAN2G(2467, 11), /* Channel 12 */
64 CHAN2G(2472, 12), /* Channel 13 */
65 CHAN2G(2484, 13), /* Channel 14 */
66};
67
68/* Some 5 GHz radios are actually tunable on XXXX-YYYY
69 * on 5 MHz steps, we support the channels which we know
70 * we have calibration data for all cards though to make
71 * this static */
72static struct ieee80211_channel ath9k_5ghz_chantable[] = {
73 /* _We_ call this UNII 1 */
74 CHAN5G(5180, 14), /* Channel 36 */
75 CHAN5G(5200, 15), /* Channel 40 */
76 CHAN5G(5220, 16), /* Channel 44 */
77 CHAN5G(5240, 17), /* Channel 48 */
78 /* _We_ call this UNII 2 */
79 CHAN5G(5260, 18), /* Channel 52 */
80 CHAN5G(5280, 19), /* Channel 56 */
81 CHAN5G(5300, 20), /* Channel 60 */
82 CHAN5G(5320, 21), /* Channel 64 */
83 /* _We_ call this "Middle band" */
84 CHAN5G(5500, 22), /* Channel 100 */
85 CHAN5G(5520, 23), /* Channel 104 */
86 CHAN5G(5540, 24), /* Channel 108 */
87 CHAN5G(5560, 25), /* Channel 112 */
88 CHAN5G(5580, 26), /* Channel 116 */
89 CHAN5G(5600, 27), /* Channel 120 */
90 CHAN5G(5620, 28), /* Channel 124 */
91 CHAN5G(5640, 29), /* Channel 128 */
92 CHAN5G(5660, 30), /* Channel 132 */
93 CHAN5G(5680, 31), /* Channel 136 */
94 CHAN5G(5700, 32), /* Channel 140 */
95 /* _We_ call this UNII 3 */
96 CHAN5G(5745, 33), /* Channel 149 */
97 CHAN5G(5765, 34), /* Channel 153 */
98 CHAN5G(5785, 35), /* Channel 157 */
99 CHAN5G(5805, 36), /* Channel 161 */
100 CHAN5G(5825, 37), /* Channel 165 */
101};
102
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800103static void ath_cache_conf_rate(struct ath_softc *sc,
104 struct ieee80211_conf *conf)
Sujithff37e332008-11-24 12:07:55 +0530105{
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800106 switch (conf->channel->band) {
107 case IEEE80211_BAND_2GHZ:
108 if (conf_is_ht20(conf))
109 sc->cur_rate_table =
110 sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
111 else if (conf_is_ht40_minus(conf))
112 sc->cur_rate_table =
113 sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
114 else if (conf_is_ht40_plus(conf))
115 sc->cur_rate_table =
116 sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800117 else
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800118 sc->cur_rate_table =
119 sc->hw_rate_table[ATH9K_MODE_11G];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800120 break;
121 case IEEE80211_BAND_5GHZ:
122 if (conf_is_ht20(conf))
123 sc->cur_rate_table =
124 sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
125 else if (conf_is_ht40_minus(conf))
126 sc->cur_rate_table =
127 sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
128 else if (conf_is_ht40_plus(conf))
129 sc->cur_rate_table =
130 sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
131 else
Luis R. Rodriguez96742252008-12-23 15:58:38 -0800132 sc->cur_rate_table =
133 sc->hw_rate_table[ATH9K_MODE_11A];
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800134 break;
135 default:
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800136 BUG_ON(1);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800137 break;
138 }
Sujithff37e332008-11-24 12:07:55 +0530139}
140
141static void ath_update_txpow(struct ath_softc *sc)
142{
Sujithcbe61d82009-02-09 13:27:12 +0530143 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530144 u32 txpow;
145
Sujith17d79042009-02-09 13:27:03 +0530146 if (sc->curtxpow != sc->config.txpowlimit) {
147 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +0530148 /* read back in case value is clamped */
149 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
Sujith17d79042009-02-09 13:27:03 +0530150 sc->curtxpow = txpow;
Sujithff37e332008-11-24 12:07:55 +0530151 }
152}
153
154static u8 parse_mpdudensity(u8 mpdudensity)
155{
156 /*
157 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
158 * 0 for no restriction
159 * 1 for 1/4 us
160 * 2 for 1/2 us
161 * 3 for 1 us
162 * 4 for 2 us
163 * 5 for 4 us
164 * 6 for 8 us
165 * 7 for 16 us
166 */
167 switch (mpdudensity) {
168 case 0:
169 return 0;
170 case 1:
171 case 2:
172 case 3:
173 /* Our lower layer calculations limit our precision to
174 1 microsecond */
175 return 1;
176 case 4:
177 return 2;
178 case 5:
179 return 4;
180 case 6:
181 return 8;
182 case 7:
183 return 16;
184 default:
185 return 0;
186 }
187}
188
189static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
190{
Luis R. Rodriguez4f0fc7c2009-05-06 02:20:00 -0400191 const struct ath_rate_table *rate_table = NULL;
Sujithff37e332008-11-24 12:07:55 +0530192 struct ieee80211_supported_band *sband;
193 struct ieee80211_rate *rate;
194 int i, maxrates;
195
196 switch (band) {
197 case IEEE80211_BAND_2GHZ:
198 rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
199 break;
200 case IEEE80211_BAND_5GHZ:
201 rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
202 break;
203 default:
204 break;
205 }
206
207 if (rate_table == NULL)
208 return;
209
210 sband = &sc->sbands[band];
211 rate = sc->rates[band];
212
213 if (rate_table->rate_cnt > ATH_RATE_MAX)
214 maxrates = ATH_RATE_MAX;
215 else
216 maxrates = rate_table->rate_cnt;
217
218 for (i = 0; i < maxrates; i++) {
219 rate[i].bitrate = rate_table->info[i].ratekbps / 100;
220 rate[i].hw_value = rate_table->info[i].ratecode;
Sujithf46730d2009-01-27 13:51:03 +0530221 if (rate_table->info[i].short_preamble) {
222 rate[i].hw_value_short = rate_table->info[i].ratecode |
223 rate_table->info[i].short_preamble;
224 rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
225 }
Sujithff37e332008-11-24 12:07:55 +0530226 sband->n_bitrates++;
Sujithf46730d2009-01-27 13:51:03 +0530227
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700228 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
Sujith04bd46382008-11-28 22:18:05 +0530229 rate[i].bitrate / 10, rate[i].hw_value);
Sujithff37e332008-11-24 12:07:55 +0530230 }
231}
232
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +0530233static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
234 struct ieee80211_hw *hw)
235{
236 struct ieee80211_channel *curchan = hw->conf.channel;
237 struct ath9k_channel *channel;
238 u8 chan_idx;
239
240 chan_idx = curchan->hw_value;
241 channel = &sc->sc_ah->channels[chan_idx];
242 ath9k_update_ichannel(sc, hw, channel);
243 return channel;
244}
245
Sujithff37e332008-11-24 12:07:55 +0530246/*
247 * Set/change channels. If the channel is really being changed, it's done
248 * by reseting the chip. To accomplish this we must first cleanup any pending
249 * DMA, then restart stuff.
250*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200251int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
252 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530253{
Sujithcbe61d82009-02-09 13:27:12 +0530254 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530255 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800256 struct ieee80211_channel *channel = hw->conf.channel;
257 int r;
Sujithff37e332008-11-24 12:07:55 +0530258
259 if (sc->sc_flags & SC_OP_INVALID)
260 return -EIO;
261
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530262 ath9k_ps_wakeup(sc);
263
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800264 /*
265 * This is only performed if the channel settings have
266 * actually changed.
267 *
268 * To switch channels clear any pending DMA operations;
269 * wait long enough for the RX fifo to drain, reset the
270 * hardware at the new frequency, and then re-enable
271 * the relevant bits of the h/w.
272 */
273 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530274 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800275 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530276
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800277 /* XXX: do not flush receive queue here. We don't want
278 * to flush data frames already in queue because of
279 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530280
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800281 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
282 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530283
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700284 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800285 "(%u MHz) -> (%u MHz), chanwidth: %d\n",
Sujith2660b812009-02-09 13:27:26 +0530286 sc->sc_ah->curchan->channel,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800287 channel->center_freq, sc->tx_chan_width);
Sujith99405f92008-11-24 12:08:35 +0530288
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800289 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800290
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800291 r = ath9k_hw_reset(ah, hchan, fastcc);
292 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700293 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800294 "Unable to reset channel (%u Mhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +0530295 "reset status %d\n",
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800296 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530297 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200298 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530299 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800300 spin_unlock_bh(&sc->sc_resetlock);
301
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800302 sc->sc_flags &= ~SC_OP_FULL_RESET;
303
304 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700305 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800306 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200307 r = -EIO;
308 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800309 }
310
311 ath_cache_conf_rate(sc, &hw->conf);
312 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530313 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200314
315 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530316 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200317 return r;
Sujithff37e332008-11-24 12:07:55 +0530318}
319
320/*
321 * This routine performs the periodic noise floor calibration function
322 * that is used to adjust and optimize the chip performance. This
323 * takes environmental changes (location, temperature) into account.
324 * When the task is complete, it reschedules itself depending on the
325 * appropriate interval that was calculated.
326 */
327static void ath_ani_calibrate(unsigned long data)
328{
Sujith20977d32009-02-20 15:13:28 +0530329 struct ath_softc *sc = (struct ath_softc *)data;
330 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530331 bool longcal = false;
332 bool shortcal = false;
333 bool aniflag = false;
334 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530335 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530336
Sujith20977d32009-02-20 15:13:28 +0530337 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
338 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530339
340 /*
341 * don't calibrate when we're scanning.
342 * we are most likely not on our home channel.
343 */
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530344 spin_lock(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +0530345 if (sc->sc_flags & SC_OP_SCANNING)
Sujith20977d32009-02-20 15:13:28 +0530346 goto set_timer;
Sujithff37e332008-11-24 12:07:55 +0530347
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300348 /* Only calibrate if awake */
349 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
350 goto set_timer;
351
352 ath9k_ps_wakeup(sc);
353
Sujithff37e332008-11-24 12:07:55 +0530354 /* Long calibration runs independently of short calibration. */
Sujith17d79042009-02-09 13:27:03 +0530355 if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530356 longcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700357 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530358 sc->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530359 }
360
Sujith17d79042009-02-09 13:27:03 +0530361 /* Short calibration applies only while caldone is false */
362 if (!sc->ani.caldone) {
Sujith20977d32009-02-20 15:13:28 +0530363 if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530364 shortcal = true;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700365 DPRINTF(sc->sc_ah, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
Sujith17d79042009-02-09 13:27:03 +0530366 sc->ani.shortcal_timer = timestamp;
367 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530368 }
369 } else {
Sujith17d79042009-02-09 13:27:03 +0530370 if ((timestamp - sc->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530371 ATH_RESTART_CALINTERVAL) {
Sujith17d79042009-02-09 13:27:03 +0530372 sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
373 if (sc->ani.caldone)
374 sc->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530375 }
376 }
377
378 /* Verify whether we must check ANI */
Sujith20977d32009-02-20 15:13:28 +0530379 if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530380 aniflag = true;
Sujith17d79042009-02-09 13:27:03 +0530381 sc->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530382 }
383
384 /* Skip all processing if there's nothing to do. */
385 if (longcal || shortcal || aniflag) {
386 /* Call ANI routine if necessary */
387 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530388 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530389
390 /* Perform calibration if necessary */
391 if (longcal || shortcal) {
Sujith379f0442009-04-13 21:56:48 +0530392 sc->ani.caldone = ath9k_hw_calibrate(ah, ah->curchan,
393 sc->rx_chainmask, longcal);
Sujithff37e332008-11-24 12:07:55 +0530394
Sujith379f0442009-04-13 21:56:48 +0530395 if (longcal)
396 sc->ani.noise_floor = ath9k_hw_getchan_noise(ah,
397 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530398
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700399 DPRINTF(sc->sc_ah, ATH_DBG_ANI," calibrate chan %u/%x nf: %d\n",
Sujith379f0442009-04-13 21:56:48 +0530400 ah->curchan->channel, ah->curchan->channelFlags,
401 sc->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530402 }
403 }
404
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300405 ath9k_ps_restore(sc);
406
Sujith20977d32009-02-20 15:13:28 +0530407set_timer:
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +0530408 spin_unlock(&sc->ani_lock);
Sujithff37e332008-11-24 12:07:55 +0530409 /*
410 * Set timer interval based on previous results.
411 * The interval must be the shortest necessary to satisfy ANI,
412 * short calibration and long calibration.
413 */
Sujithaac92072008-12-02 18:37:54 +0530414 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530415 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530416 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Sujith17d79042009-02-09 13:27:03 +0530417 if (!sc->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530418 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530419
Sujith17d79042009-02-09 13:27:03 +0530420 mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530421}
422
Sujith415f7382009-04-13 21:56:46 +0530423static void ath_start_ani(struct ath_softc *sc)
424{
425 unsigned long timestamp = jiffies_to_msecs(jiffies);
426
427 sc->ani.longcal_timer = timestamp;
428 sc->ani.shortcal_timer = timestamp;
429 sc->ani.checkani_timer = timestamp;
430
431 mod_timer(&sc->ani.timer,
432 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
433}
434
Sujithff37e332008-11-24 12:07:55 +0530435/*
436 * Update tx/rx chainmask. For legacy association,
437 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530438 * the chainmask configuration, for bt coexistence, use
439 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530440 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200441void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530442{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700443 struct ath_hw *ah = sc->sc_ah;
444
Sujith3d832612009-08-21 12:00:28 +0530445 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700446 (ah->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE)) {
Sujith2660b812009-02-09 13:27:26 +0530447 sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
448 sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530449 } else {
Sujith17d79042009-02-09 13:27:03 +0530450 sc->tx_chainmask = 1;
451 sc->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530452 }
453
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700454 DPRINTF(ah, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
Sujith17d79042009-02-09 13:27:03 +0530455 sc->tx_chainmask, sc->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530456}
457
458static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
459{
460 struct ath_node *an;
461
462 an = (struct ath_node *)sta->drv_priv;
463
Sujith87792ef2009-03-30 15:28:48 +0530464 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530465 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530466 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530467 sta->ht_cap.ampdu_factor);
468 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400469 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530470 }
Sujithff37e332008-11-24 12:07:55 +0530471}
472
473static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
474{
475 struct ath_node *an = (struct ath_node *)sta->drv_priv;
476
477 if (sc->sc_flags & SC_OP_TXAGGR)
478 ath_tx_node_cleanup(sc, an);
479}
480
481static void ath9k_tasklet(unsigned long data)
482{
483 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700484 struct ath_hw *ah = sc->sc_ah;
485
Sujith17d79042009-02-09 13:27:03 +0530486 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530487
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400488 ath9k_ps_wakeup(sc);
489
Sujithff37e332008-11-24 12:07:55 +0530490 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530491 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400492 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530493 return;
Sujithff37e332008-11-24 12:07:55 +0530494 }
495
Sujith063d8be2009-03-30 15:28:49 +0530496 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
497 spin_lock_bh(&sc->rx.rxflushlock);
498 ath_rx_tasklet(sc, 0);
499 spin_unlock_bh(&sc->rx.rxflushlock);
500 }
501
502 if (status & ATH9K_INT_TX)
503 ath_tx_tasklet(sc);
504
Gabor Juhos96148322009-07-24 17:27:21 +0200505 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300506 /*
507 * TSF sync does not look correct; remain awake to sync with
508 * the next Beacon.
509 */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700510 DPRINTF(ah, ATH_DBG_PS, "TSFOOR - Sync with next Beacon\n");
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300511 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON | SC_OP_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300512 }
513
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700514 if (ah->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530515 if (status & ATH9K_INT_GENTIMER)
516 ath_gen_timer_isr(sc->sc_ah);
517
Sujithff37e332008-11-24 12:07:55 +0530518 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700519 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400520 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530521}
522
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100523irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530524{
Sujith063d8be2009-03-30 15:28:49 +0530525#define SCHED_INTR ( \
526 ATH9K_INT_FATAL | \
527 ATH9K_INT_RXORN | \
528 ATH9K_INT_RXEOL | \
529 ATH9K_INT_RX | \
530 ATH9K_INT_TX | \
531 ATH9K_INT_BMISS | \
532 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530533 ATH9K_INT_TSFOOR | \
534 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530535
Sujithff37e332008-11-24 12:07:55 +0530536 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530537 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530538 enum ath9k_int status;
539 bool sched = false;
540
Sujith063d8be2009-03-30 15:28:49 +0530541 /*
542 * The hardware is not ready/present, don't
543 * touch anything. Note this can happen early
544 * on if the IRQ is shared.
545 */
546 if (sc->sc_flags & SC_OP_INVALID)
547 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530548
Sujithff37e332008-11-24 12:07:55 +0530549
Sujith063d8be2009-03-30 15:28:49 +0530550 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530551
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400552 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530553 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530554
Sujith063d8be2009-03-30 15:28:49 +0530555 /*
556 * Figure out the reason(s) for the interrupt. Note
557 * that the hal returns a pseudo-ISR that may include
558 * bits we haven't explicitly enabled so we mask the
559 * value to insure we only process bits we requested.
560 */
561 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
562 status &= sc->imask; /* discard unasked-for bits */
563
564 /*
565 * If there are no status bits set, then this interrupt was not
566 * for me (should have been caught above).
567 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400568 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530569 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530570
571 /* Cache the status */
572 sc->intrstatus = status;
573
574 if (status & SCHED_INTR)
575 sched = true;
576
577 /*
578 * If a FATAL or RXORN interrupt is received, we have to reset the
579 * chip immediately.
580 */
581 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
582 goto chip_reset;
583
584 if (status & ATH9K_INT_SWBA)
585 tasklet_schedule(&sc->bcon_tasklet);
586
587 if (status & ATH9K_INT_TXURN)
588 ath9k_hw_updatetxtriglevel(ah, true);
589
590 if (status & ATH9K_INT_MIB) {
591 /*
592 * Disable interrupts until we service the MIB
593 * interrupt; otherwise it will continue to
594 * fire.
595 */
596 ath9k_hw_set_interrupts(ah, 0);
597 /*
598 * Let the hal handle the event. We assume
599 * it will clear whatever condition caused
600 * the interrupt.
601 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530602 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530603 ath9k_hw_set_interrupts(ah, sc->imask);
604 }
605
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400606 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
607 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530608 /* Clear RxAbort bit so that we can
609 * receive frames */
610 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400611 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith063d8be2009-03-30 15:28:49 +0530612 sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
613 }
Sujith063d8be2009-03-30 15:28:49 +0530614
615chip_reset:
616
Sujith817e11d2008-12-07 21:42:44 +0530617 ath_debug_stat_interrupt(sc, status);
618
Sujithff37e332008-11-24 12:07:55 +0530619 if (sched) {
620 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530621 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530622 tasklet_schedule(&sc->intr_tq);
623 }
624
625 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530626
627#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530628}
629
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700630static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530631 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530632 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700633{
634 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700635
636 switch (chan->band) {
637 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530638 switch(channel_type) {
639 case NL80211_CHAN_NO_HT:
640 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700641 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530642 break;
643 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700644 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530645 break;
646 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700647 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530648 break;
649 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700650 break;
651 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530652 switch(channel_type) {
653 case NL80211_CHAN_NO_HT:
654 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700655 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530656 break;
657 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700658 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530659 break;
660 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700661 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530662 break;
663 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700664 break;
665 default:
666 break;
667 }
668
669 return chanmode;
670}
671
Jouni Malinen6ace2892008-12-17 13:32:17 +0200672static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200673 struct ath9k_keyval *hk, const u8 *addr,
674 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700675{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200676 const u8 *key_rxmic;
677 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700678
Jouni Malinen6ace2892008-12-17 13:32:17 +0200679 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
680 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700681
682 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200683 /*
684 * Group key installation - only two key cache entries are used
685 * regardless of splitmic capability since group key is only
686 * used either for TX or RX.
687 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200688 if (authenticator) {
689 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
690 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
691 } else {
692 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
693 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
694 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200695 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700696 }
Sujith17d79042009-02-09 13:27:03 +0530697 if (!sc->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200698 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700699 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
700 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200701 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700702 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200703
704 /* Separate key cache entries for TX and RX */
705
706 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700707 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Jouni Malinend216aaa2009-03-03 13:11:53 +0200708 if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
709 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700710 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +0530711 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700712 return 0;
713 }
714
715 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
716 /* XXX delete tx key on failure? */
Jouni Malinend216aaa2009-03-03 13:11:53 +0200717 return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200718}
719
720static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
721{
722 int i;
723
Sujith17d79042009-02-09 13:27:03 +0530724 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
725 if (test_bit(i, sc->keymap) ||
726 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200727 continue; /* At least one part of TKIP key allocated */
Sujith17d79042009-02-09 13:27:03 +0530728 if (sc->splitmic &&
729 (test_bit(i + 32, sc->keymap) ||
730 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200731 continue; /* At least one part of TKIP key allocated */
732
733 /* Found a free slot for a TKIP key */
734 return i;
735 }
736 return -1;
737}
738
739static int ath_reserve_key_cache_slot(struct ath_softc *sc)
740{
741 int i;
742
743 /* First, try to find slots that would not be available for TKIP. */
Sujith17d79042009-02-09 13:27:03 +0530744 if (sc->splitmic) {
745 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
746 if (!test_bit(i, sc->keymap) &&
747 (test_bit(i + 32, sc->keymap) ||
748 test_bit(i + 64, sc->keymap) ||
749 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200750 return i;
Sujith17d79042009-02-09 13:27:03 +0530751 if (!test_bit(i + 32, sc->keymap) &&
752 (test_bit(i, sc->keymap) ||
753 test_bit(i + 64, sc->keymap) ||
754 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200755 return i + 32;
Sujith17d79042009-02-09 13:27:03 +0530756 if (!test_bit(i + 64, sc->keymap) &&
757 (test_bit(i , sc->keymap) ||
758 test_bit(i + 32, sc->keymap) ||
759 test_bit(i + 64 + 32, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200760 return i + 64;
Sujith17d79042009-02-09 13:27:03 +0530761 if (!test_bit(i + 64 + 32, sc->keymap) &&
762 (test_bit(i, sc->keymap) ||
763 test_bit(i + 32, sc->keymap) ||
764 test_bit(i + 64, sc->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200765 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200766 }
767 } else {
Sujith17d79042009-02-09 13:27:03 +0530768 for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
769 if (!test_bit(i, sc->keymap) &&
770 test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200771 return i;
Sujith17d79042009-02-09 13:27:03 +0530772 if (test_bit(i, sc->keymap) &&
773 !test_bit(i + 64, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200774 return i + 64;
775 }
776 }
777
778 /* No partially used TKIP slots, pick any available slot */
Sujith17d79042009-02-09 13:27:03 +0530779 for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200780 /* Do not allow slots that could be needed for TKIP group keys
781 * to be used. This limitation could be removed if we know that
782 * TKIP will not be used. */
783 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
784 continue;
Sujith17d79042009-02-09 13:27:03 +0530785 if (sc->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200786 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
787 continue;
788 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
789 continue;
790 }
791
Sujith17d79042009-02-09 13:27:03 +0530792 if (!test_bit(i, sc->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200793 return i; /* Found a free slot for a key */
794 }
795
796 /* No free slot found */
797 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700798}
799
800static int ath_key_config(struct ath_softc *sc,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200801 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100802 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803 struct ieee80211_key_conf *key)
804{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700805 struct ath9k_keyval hk;
806 const u8 *mac = NULL;
807 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200808 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700809
810 memset(&hk, 0, sizeof(hk));
811
812 switch (key->alg) {
813 case ALG_WEP:
814 hk.kv_type = ATH9K_CIPHER_WEP;
815 break;
816 case ALG_TKIP:
817 hk.kv_type = ATH9K_CIPHER_TKIP;
818 break;
819 case ALG_CCMP:
820 hk.kv_type = ATH9K_CIPHER_AES_CCM;
821 break;
822 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200823 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700824 }
825
Jouni Malinen6ace2892008-12-17 13:32:17 +0200826 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700827 memcpy(hk.kv_val, key->key, key->keylen);
828
Jouni Malinen6ace2892008-12-17 13:32:17 +0200829 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
830 /* For now, use the default keys for broadcast keys. This may
831 * need to change with virtual interfaces. */
832 idx = key->keyidx;
833 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100834 if (WARN_ON(!sta))
835 return -EOPNOTSUPP;
836 mac = sta->addr;
837
Jouni Malinen6ace2892008-12-17 13:32:17 +0200838 if (vif->type != NL80211_IFTYPE_AP) {
839 /* Only keyidx 0 should be used with unicast key, but
840 * allow this for client mode for now. */
841 idx = key->keyidx;
842 } else
843 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700844 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100845 if (WARN_ON(!sta))
846 return -EOPNOTSUPP;
847 mac = sta->addr;
848
Jouni Malinen6ace2892008-12-17 13:32:17 +0200849 if (key->alg == ALG_TKIP)
850 idx = ath_reserve_key_cache_slot_tkip(sc);
851 else
852 idx = ath_reserve_key_cache_slot(sc);
853 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200854 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700855 }
856
857 if (key->alg == ALG_TKIP)
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200858 ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
859 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700860 else
Jouni Malinend216aaa2009-03-03 13:11:53 +0200861 ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700862
863 if (!ret)
864 return -EIO;
865
Sujith17d79042009-02-09 13:27:03 +0530866 set_bit(idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200867 if (key->alg == ALG_TKIP) {
Sujith17d79042009-02-09 13:27:03 +0530868 set_bit(idx + 64, sc->keymap);
869 if (sc->splitmic) {
870 set_bit(idx + 32, sc->keymap);
871 set_bit(idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200872 }
873 }
874
875 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700876}
877
878static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
879{
Jouni Malinen6ace2892008-12-17 13:32:17 +0200880 ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
881 if (key->hw_key_idx < IEEE80211_WEP_NKID)
882 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700883
Sujith17d79042009-02-09 13:27:03 +0530884 clear_bit(key->hw_key_idx, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200885 if (key->alg != ALG_TKIP)
886 return;
887
Sujith17d79042009-02-09 13:27:03 +0530888 clear_bit(key->hw_key_idx + 64, sc->keymap);
889 if (sc->splitmic) {
890 clear_bit(key->hw_key_idx + 32, sc->keymap);
891 clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200892 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700893}
894
Sujitheb2599c2009-01-23 11:20:44 +0530895static void setup_ht_cap(struct ath_softc *sc,
896 struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700897{
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530898 u8 tx_streams, rx_streams;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700899
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200900 ht_info->ht_supported = true;
901 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
902 IEEE80211_HT_CAP_SM_PS |
903 IEEE80211_HT_CAP_SGI_40 |
904 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700905
Sujith9e98ac62009-07-23 15:32:34 +0530906 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
907 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
Sujitheb2599c2009-01-23 11:20:44 +0530908
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200909 /* set up supported mcs set */
910 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530911 tx_streams = !(sc->tx_chainmask & (sc->tx_chainmask - 1)) ? 1 : 2;
912 rx_streams = !(sc->rx_chainmask & (sc->rx_chainmask - 1)) ? 1 : 2;
Sujitheb2599c2009-01-23 11:20:44 +0530913
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530914 if (tx_streams != rx_streams) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700915 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "TX streams %d, RX streams: %d\n",
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530916 tx_streams, rx_streams);
917 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
918 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
919 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
Sujitheb2599c2009-01-23 11:20:44 +0530920 }
921
Senthil Balasubramanian140add22009-06-24 18:56:42 +0530922 ht_info->mcs.rx_mask[0] = 0xff;
923 if (rx_streams >= 2)
924 ht_info->mcs.rx_mask[1] = 0xff;
925
926 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700927}
928
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530929static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530930 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530931 struct ieee80211_bss_conf *bss_conf)
932{
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530933
934 if (bss_conf->assoc) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700935 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
Sujith17d79042009-02-09 13:27:03 +0530936 bss_conf->aid, sc->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530937
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530938 /* New association, store aid */
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530939 sc->curaid = bss_conf->aid;
940 ath9k_hw_write_associd(sc);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300941
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530942 /*
943 * Request a re-configuration of Beacon related timers
944 * on the receipt of the first Beacon frame (i.e.,
945 * after time sync with the AP).
946 */
947 sc->sc_flags |= SC_OP_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530948
949 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200950 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530951
952 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530953 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530954
Sujith415f7382009-04-13 21:56:46 +0530955 ath_start_ani(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530956 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -0700957 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Sujith17d79042009-02-09 13:27:03 +0530958 sc->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +0530959 /* Stop ANI */
960 del_timer_sync(&sc->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530961 }
962}
963
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530964/********************************/
965/* LED functions */
966/********************************/
967
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530968static void ath_led_blink_work(struct work_struct *work)
969{
970 struct ath_softc *sc = container_of(work, struct ath_softc,
971 ath_led_blink_work.work);
972
973 if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
974 return;
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530975
976 if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
977 (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530978 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530979 else
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530980 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530981 (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530982
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400983 ieee80211_queue_delayed_work(sc->hw,
984 &sc->ath_led_blink_work,
985 (sc->sc_flags & SC_OP_LED_ON) ?
986 msecs_to_jiffies(sc->led_off_duration) :
987 msecs_to_jiffies(sc->led_on_duration));
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530988
Vasanthakumar Thiagarajan85067c02009-03-14 19:59:41 +0530989 sc->led_on_duration = sc->led_on_cnt ?
990 max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
991 ATH_LED_ON_DURATION_IDLE;
992 sc->led_off_duration = sc->led_off_cnt ?
993 max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
994 ATH_LED_OFF_DURATION_IDLE;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +0530995 sc->led_on_cnt = sc->led_off_cnt = 0;
996 if (sc->sc_flags & SC_OP_LED_ON)
997 sc->sc_flags &= ~SC_OP_LED_ON;
998 else
999 sc->sc_flags |= SC_OP_LED_ON;
1000}
1001
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301002static void ath_led_brightness(struct led_classdev *led_cdev,
1003 enum led_brightness brightness)
1004{
1005 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
1006 struct ath_softc *sc = led->sc;
1007
1008 switch (brightness) {
1009 case LED_OFF:
1010 if (led->led_type == ATH_LED_ASSOC ||
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301011 led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301012 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301013 (led->led_type == ATH_LED_RADIO));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301014 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301015 if (led->led_type == ATH_LED_RADIO)
1016 sc->sc_flags &= ~SC_OP_LED_ON;
1017 } else {
1018 sc->led_off_cnt++;
1019 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301020 break;
1021 case LED_FULL:
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301022 if (led->led_type == ATH_LED_ASSOC) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301023 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001024 ieee80211_queue_delayed_work(sc->hw,
1025 &sc->ath_led_blink_work, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301026 } else if (led->led_type == ATH_LED_RADIO) {
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301027 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301028 sc->sc_flags |= SC_OP_LED_ON;
1029 } else {
1030 sc->led_on_cnt++;
1031 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301032 break;
1033 default:
1034 break;
1035 }
1036}
1037
1038static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
1039 char *trigger)
1040{
1041 int ret;
1042
1043 led->sc = sc;
1044 led->led_cdev.name = led->name;
1045 led->led_cdev.default_trigger = trigger;
1046 led->led_cdev.brightness_set = ath_led_brightness;
1047
1048 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
1049 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001050 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301051 "Failed to register led:%s", led->name);
1052 else
1053 led->registered = 1;
1054 return ret;
1055}
1056
1057static void ath_unregister_led(struct ath_led *led)
1058{
1059 if (led->registered) {
1060 led_classdev_unregister(&led->led_cdev);
1061 led->registered = 0;
1062 }
1063}
1064
1065static void ath_deinit_leds(struct ath_softc *sc)
1066{
1067 ath_unregister_led(&sc->assoc_led);
1068 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
1069 ath_unregister_led(&sc->tx_led);
1070 ath_unregister_led(&sc->rx_led);
1071 ath_unregister_led(&sc->radio_led);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301072 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301073}
1074
1075static void ath_init_leds(struct ath_softc *sc)
1076{
1077 char *trigger;
1078 int ret;
1079
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301080 if (AR_SREV_9287(sc->sc_ah))
1081 sc->sc_ah->led_pin = ATH_LED_PIN_9287;
1082 else
1083 sc->sc_ah->led_pin = ATH_LED_PIN_DEF;
1084
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301085 /* Configure gpio 1 for output */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301086 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301087 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1088 /* LED off, active low */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301089 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301090
Vasanthakumar Thiagarajanf2bffa72009-01-29 17:52:19 +05301091 INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
1092
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301093 trigger = ieee80211_get_radio_led_name(sc->hw);
1094 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001095 "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301096 ret = ath_register_led(sc, &sc->radio_led, trigger);
1097 sc->radio_led.led_type = ATH_LED_RADIO;
1098 if (ret)
1099 goto fail;
1100
1101 trigger = ieee80211_get_assoc_led_name(sc->hw);
1102 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001103 "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301104 ret = ath_register_led(sc, &sc->assoc_led, trigger);
1105 sc->assoc_led.led_type = ATH_LED_ASSOC;
1106 if (ret)
1107 goto fail;
1108
1109 trigger = ieee80211_get_tx_led_name(sc->hw);
1110 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001111 "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301112 ret = ath_register_led(sc, &sc->tx_led, trigger);
1113 sc->tx_led.led_type = ATH_LED_TX;
1114 if (ret)
1115 goto fail;
1116
1117 trigger = ieee80211_get_rx_led_name(sc->hw);
1118 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
Danny Kukawka0818cb82009-01-31 15:52:09 +01001119 "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301120 ret = ath_register_led(sc, &sc->rx_led, trigger);
1121 sc->rx_led.led_type = ATH_LED_RX;
1122 if (ret)
1123 goto fail;
1124
1125 return;
1126
1127fail:
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001128 cancel_delayed_work_sync(&sc->ath_led_blink_work);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301129 ath_deinit_leds(sc);
1130}
1131
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001132void ath_radio_enable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301133{
Sujithcbe61d82009-02-09 13:27:12 +05301134 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001135 struct ieee80211_channel *channel = sc->hw->conf.channel;
1136 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301137
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301138 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301139 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +05301140
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301141 if (!ah->curchan)
1142 ah->curchan = ath_get_curchannel(sc, sc->hw);
1143
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301144 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301145 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001146 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001147 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001148 "Unable to reset channel %u (%uMhz) ",
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301149 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001150 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301151 }
1152 spin_unlock_bh(&sc->sc_resetlock);
1153
1154 ath_update_txpow(sc);
1155 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001156 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301157 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301158 return;
1159 }
1160
1161 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001162 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301163
1164 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +05301165 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301166
1167 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301168 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301169 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301170 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301171
1172 ieee80211_wake_queues(sc->hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301173 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301174}
1175
Jouni Malinen7ec3e512009-03-03 19:23:37 +02001176void ath_radio_disable(struct ath_softc *sc)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301177{
Sujithcbe61d82009-02-09 13:27:12 +05301178 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001179 struct ieee80211_channel *channel = sc->hw->conf.channel;
1180 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301181
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301182 ath9k_ps_wakeup(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301183 ieee80211_stop_queues(sc->hw);
1184
1185 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +05301186 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1187 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301188
1189 /* Disable interrupts */
1190 ath9k_hw_set_interrupts(ah, 0);
1191
Sujith043a0402009-01-16 21:38:47 +05301192 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301193 ath_stoprecv(sc); /* turn off frame recv */
1194 ath_flushrecv(sc); /* flush recv queue */
1195
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +05301196 if (!ah->curchan)
1197 ah->curchan = ath_get_curchannel(sc, sc->hw);
1198
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301199 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301200 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001201 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001202 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301203 "Unable to reset channel %u (%uMhz) "
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301204 "reset status %d\n",
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001205 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301206 }
1207 spin_unlock_bh(&sc->sc_resetlock);
1208
1209 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +05301210 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301211 ath9k_ps_restore(sc);
Gabor Juhos38ab4222009-06-17 20:53:21 +02001212 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301213}
1214
Gabor Juhos5077fd32009-03-06 11:17:55 +01001215/*******************/
1216/* Rfkill */
1217/*******************/
1218
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301219static bool ath_is_rfkill_set(struct ath_softc *sc)
1220{
Sujithcbe61d82009-02-09 13:27:12 +05301221 struct ath_hw *ah = sc->sc_ah;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301222
Sujith2660b812009-02-09 13:27:26 +05301223 return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
1224 ah->rfkill_polarity;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301225}
1226
Johannes Berg3b319aa2009-06-13 14:50:26 +05301227static void ath9k_rfkill_poll_state(struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301228{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301229 struct ath_wiphy *aphy = hw->priv;
1230 struct ath_softc *sc = aphy->sc;
1231 bool blocked = !!ath_is_rfkill_set(sc);
1232
1233 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
Johannes Berg19d337d2009-06-02 13:01:37 +02001234}
1235
Johannes Berg3b319aa2009-06-13 14:50:26 +05301236static void ath_start_rfkill_poll(struct ath_softc *sc)
Johannes Berg19d337d2009-06-02 13:01:37 +02001237{
Johannes Berg3b319aa2009-06-13 14:50:26 +05301238 struct ath_hw *ah = sc->sc_ah;
Johannes Berg19d337d2009-06-02 13:01:37 +02001239
Johannes Berg3b319aa2009-06-13 14:50:26 +05301240 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1241 wiphy_rfkill_start_polling(sc->hw->wiphy);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301242}
1243
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001244void ath_cleanup(struct ath_softc *sc)
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001245{
1246 ath_detach(sc);
1247 free_irq(sc->irq, sc);
1248 ath_bus_cleanup(sc);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001249 kfree(sc->sec_wiphy);
Gabor Juhos39c3c2f2009-01-14 20:17:05 +01001250 ieee80211_free_hw(sc->hw);
1251}
1252
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001253void ath_detach(struct ath_softc *sc)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301254{
1255 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001256 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05301257 int i = 0;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301258
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301259 ath9k_ps_wakeup(sc);
1260
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001261 dev_dbg(sc->dev, "Detach ATH hw\n");
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301262
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001263 ath_deinit_leds(sc);
Sujithe31f7b92009-09-23 13:49:12 +05301264 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Luis R. Rodriguez35c95ab2009-07-27 11:53:03 -07001265
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001266 for (i = 0; i < sc->num_sec_wiphy; i++) {
1267 struct ath_wiphy *aphy = sc->sec_wiphy[i];
1268 if (aphy == NULL)
1269 continue;
1270 sc->sec_wiphy[i] = NULL;
1271 ieee80211_unregister_hw(aphy->hw);
1272 ieee80211_free_hw(aphy->hw);
1273 }
Vasanthakumar Thiagarajan3fcdfb42008-11-18 01:19:56 +05301274 ieee80211_unregister_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301275 ath_rx_cleanup(sc);
1276 ath_tx_cleanup(sc);
1277
Sujith9c84b792008-10-29 10:17:13 +05301278 tasklet_kill(&sc->intr_tq);
1279 tasklet_kill(&sc->bcon_tasklet);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301280
Sujith9c84b792008-10-29 10:17:13 +05301281 if (!(sc->sc_flags & SC_OP_INVALID))
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001282 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301283
Sujith9c84b792008-10-29 10:17:13 +05301284 /* cleanup tx queues */
1285 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1286 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301287 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith9c84b792008-10-29 10:17:13 +05301288
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001289 if ((ah->btcoex_info.no_stomp_timer) &&
1290 ah->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
1291 ath_gen_timer_free(ah, ah->btcoex_info.no_stomp_timer);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301292
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001293 ath9k_hw_detach(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001294 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001295 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301296}
1297
Bob Copelande3bb2492009-03-30 22:30:30 -04001298static int ath9k_reg_notifier(struct wiphy *wiphy,
1299 struct regulatory_request *request)
1300{
1301 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
1302 struct ath_wiphy *aphy = hw->priv;
1303 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001304 struct ath_regulatory *reg = &sc->common.regulatory;
Bob Copelande3bb2492009-03-30 22:30:30 -04001305
1306 return ath_reg_notifier_apply(wiphy, request, reg);
1307}
1308
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001309/*
1310 * Initialize and fill ath_softc, ath_sofct is the
1311 * "Software Carrier" struct. Historically it has existed
1312 * to allow the separation between hardware specific
1313 * variables (now in ath_hw) and driver specific variables.
1314 */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301315static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid)
Sujithff37e332008-11-24 12:07:55 +05301316{
Sujithcbe61d82009-02-09 13:27:12 +05301317 struct ath_hw *ah = NULL;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001318 int r = 0, i;
Sujithff37e332008-11-24 12:07:55 +05301319 int csz = 0;
1320
1321 /* XXX: hardware will not be ready until ath_open() being called */
1322 sc->sc_flags |= SC_OP_INVALID;
Sujith88b126a2008-11-28 22:19:02 +05301323
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001324 spin_lock_init(&sc->wiphy_lock);
Sujithff37e332008-11-24 12:07:55 +05301325 spin_lock_init(&sc->sc_resetlock);
Luis R. Rodriguez61584252009-03-12 18:18:49 -04001326 spin_lock_init(&sc->sc_serial_rw);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05301327 spin_lock_init(&sc->ani_lock);
Gabor Juhos04717cc2009-07-14 20:17:13 -04001328 spin_lock_init(&sc->sc_pm_lock);
Sujithaa33de02008-12-18 11:40:16 +05301329 mutex_init(&sc->mutex);
Sujithff37e332008-11-24 12:07:55 +05301330 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith9fc9ab02009-03-03 10:16:51 +05301331 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
Sujithff37e332008-11-24 12:07:55 +05301332 (unsigned long)sc);
1333
1334 /*
1335 * Cache line size is used to size and align various
1336 * structures used to communicate with the hardware.
1337 */
Gabor Juhos88d15702009-01-14 20:17:04 +01001338 ath_read_cachesize(sc, &csz);
Sujithff37e332008-11-24 12:07:55 +05301339 /* XXX assert csz is non-zero */
Luis R. Rodriguezd15dd3e2009-08-12 09:56:59 -07001340 sc->common.cachelsz = csz << 2; /* convert to bytes */
Sujithff37e332008-11-24 12:07:55 +05301341
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001342 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
1343 if (!ah) {
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001344 r = -ENOMEM;
1345 goto bad_no_ah;
1346 }
1347
1348 ah->ah_sc = sc;
Luis R. Rodriguez8df5d1b2009-08-03 12:24:37 -07001349 ah->hw_version.devid = devid;
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301350 ah->hw_version.subsysid = subsysid;
Luis R. Rodrigueze1e2f932009-08-03 12:24:38 -07001351 sc->sc_ah = ah;
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001352
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001353 if (ath9k_init_debug(ah) < 0)
1354 dev_err(sc->dev, "Unable to create debugfs files\n");
1355
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001356 r = ath9k_hw_init(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001357 if (r) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001358 DPRINTF(ah, ATH_DBG_FATAL,
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001359 "Unable to initialize hardware; "
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001360 "initialization status: %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301361 goto bad;
1362 }
Sujithff37e332008-11-24 12:07:55 +05301363
1364 /* Get the hardware key cache size. */
Sujith2660b812009-02-09 13:27:26 +05301365 sc->keymax = ah->caps.keycache_size;
Sujith17d79042009-02-09 13:27:03 +05301366 if (sc->keymax > ATH_KEYMAX) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001367 DPRINTF(ah, ATH_DBG_ANY,
Sujith04bd46382008-11-28 22:18:05 +05301368 "Warning, using only %u entries in %u key cache\n",
Sujith17d79042009-02-09 13:27:03 +05301369 ATH_KEYMAX, sc->keymax);
1370 sc->keymax = ATH_KEYMAX;
Sujithff37e332008-11-24 12:07:55 +05301371 }
1372
1373 /*
1374 * Reset the key cache since some parts do not
1375 * reset the contents on initial power up.
1376 */
Sujith17d79042009-02-09 13:27:03 +05301377 for (i = 0; i < sc->keymax; i++)
Sujithff37e332008-11-24 12:07:55 +05301378 ath9k_hw_keyreset(ah, (u16) i);
Sujithff37e332008-11-24 12:07:55 +05301379
Sujithff37e332008-11-24 12:07:55 +05301380 /* default to MONITOR mode */
Sujith2660b812009-02-09 13:27:26 +05301381 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
Colin McCabed97809d2008-12-01 13:38:55 -08001382
Sujithff37e332008-11-24 12:07:55 +05301383 /* Setup rate tables */
1384
1385 ath_rate_attach(sc);
1386 ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
1387 ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
1388
1389 /*
1390 * Allocate hardware transmit queues: one queue for
1391 * beacon frames and one data queue for each QoS
1392 * priority. Note that the hal handles reseting
1393 * these queues at the needed time.
1394 */
Sujithb77f4832008-12-07 21:44:03 +05301395 sc->beacon.beaconq = ath_beaconq_setup(ah);
1396 if (sc->beacon.beaconq == -1) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001397 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301398 "Unable to setup a beacon xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001399 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301400 goto bad2;
1401 }
Sujithb77f4832008-12-07 21:44:03 +05301402 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
1403 if (sc->beacon.cabq == NULL) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001404 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301405 "Unable to setup CAB xmit queue\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001406 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301407 goto bad2;
1408 }
1409
Sujith17d79042009-02-09 13:27:03 +05301410 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
Sujithff37e332008-11-24 12:07:55 +05301411 ath_cabq_update(sc);
1412
Sujithb77f4832008-12-07 21:44:03 +05301413 for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
1414 sc->tx.hwq_map[i] = -1;
Sujithff37e332008-11-24 12:07:55 +05301415
1416 /* Setup data queues */
1417 /* NB: ensure BK queue is the lowest priority h/w queue */
1418 if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001419 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301420 "Unable to setup xmit queue for BK traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001421 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301422 goto bad2;
1423 }
1424
1425 if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001426 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301427 "Unable to setup xmit queue for BE traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001428 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301429 goto bad2;
1430 }
1431 if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001432 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301433 "Unable to setup xmit queue for VI traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001434 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301435 goto bad2;
1436 }
1437 if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001438 DPRINTF(ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05301439 "Unable to setup xmit queue for VO traffic\n");
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001440 r = -EIO;
Sujithff37e332008-11-24 12:07:55 +05301441 goto bad2;
1442 }
1443
1444 /* Initializes the noise floor to a reasonable default value.
1445 * Later on this will be updated during ANI processing. */
1446
Sujith17d79042009-02-09 13:27:03 +05301447 sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
1448 setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
Sujithff37e332008-11-24 12:07:55 +05301449
1450 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1451 ATH9K_CIPHER_TKIP, NULL)) {
1452 /*
1453 * Whether we should enable h/w TKIP MIC.
1454 * XXX: if we don't support WME TKIP MIC, then we wouldn't
1455 * report WMM capable, so it's always safe to turn on
1456 * TKIP MIC in this case.
1457 */
1458 ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
1459 0, 1, NULL);
1460 }
1461
1462 /*
1463 * Check whether the separate key cache entries
1464 * are required to handle both tx+rx MIC keys.
1465 * With split mic keys the number of stations is limited
1466 * to 27 otherwise 59.
1467 */
1468 if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1469 ATH9K_CIPHER_TKIP, NULL)
1470 && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
1471 ATH9K_CIPHER_MIC, NULL)
1472 && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
1473 0, NULL))
Sujith17d79042009-02-09 13:27:03 +05301474 sc->splitmic = 1;
Sujithff37e332008-11-24 12:07:55 +05301475
1476 /* turn on mcast key search if possible */
1477 if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
1478 (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
1479 1, NULL);
1480
Sujith17d79042009-02-09 13:27:03 +05301481 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Sujithff37e332008-11-24 12:07:55 +05301482
1483 /* 11n Capabilities */
Sujith2660b812009-02-09 13:27:26 +05301484 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujithff37e332008-11-24 12:07:55 +05301485 sc->sc_flags |= SC_OP_TXAGGR;
1486 sc->sc_flags |= SC_OP_RXAGGR;
1487 }
1488
Sujith2660b812009-02-09 13:27:26 +05301489 sc->tx_chainmask = ah->caps.tx_chainmask;
1490 sc->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +05301491
1492 ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
Sujithb77f4832008-12-07 21:44:03 +05301493 sc->rx.defant = ath9k_hw_getdefantenna(ah);
Sujithff37e332008-11-24 12:07:55 +05301494
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001495 if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
Sujithba52da52009-02-09 13:27:10 +05301496 memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujithff37e332008-11-24 12:07:55 +05301497
Sujithb77f4832008-12-07 21:44:03 +05301498 sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
Sujithff37e332008-11-24 12:07:55 +05301499
1500 /* initialize beacon slots */
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001501 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001502 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001503 sc->beacon.bslot_aphy[i] = NULL;
1504 }
Sujithff37e332008-11-24 12:07:55 +05301505
Sujithff37e332008-11-24 12:07:55 +05301506 /* setup channels and rates */
1507
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001508 sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301509 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
1510 sc->rates[IEEE80211_BAND_2GHZ];
1511 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001512 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
1513 ARRAY_SIZE(ath9k_2ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301514
Sujith2660b812009-02-09 13:27:26 +05301515 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001516 sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
Sujithff37e332008-11-24 12:07:55 +05301517 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
1518 sc->rates[IEEE80211_BAND_5GHZ];
1519 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001520 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
1521 ARRAY_SIZE(ath9k_5ghz_chantable);
Sujithff37e332008-11-24 12:07:55 +05301522 }
1523
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001524 if (ah->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE) {
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301525 r = ath9k_hw_btcoex_init(ah);
1526 if (r)
1527 goto bad2;
1528 }
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +05301529
Sujithff37e332008-11-24 12:07:55 +05301530 return 0;
1531bad2:
1532 /* cleanup tx queues */
1533 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1534 if (ATH_TXQ_SETUP(sc, i))
Sujithb77f4832008-12-07 21:44:03 +05301535 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujithff37e332008-11-24 12:07:55 +05301536bad:
Luis R. Rodriguez95fafca2009-08-03 12:24:54 -07001537 ath9k_hw_detach(ah);
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001538bad_no_ah:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001539 ath9k_exit_debug(sc->sc_ah);
1540 sc->sc_ah = NULL;
Sujithff37e332008-11-24 12:07:55 +05301541
Luis R. Rodriguez4f3acf82009-08-03 12:24:36 -07001542 return r;
Sujithff37e332008-11-24 12:07:55 +05301543}
1544
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001545void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301546{
Sujith9c84b792008-10-29 10:17:13 +05301547 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1548 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1549 IEEE80211_HW_SIGNAL_DBM |
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301550 IEEE80211_HW_AMPDU_AGGREGATION |
1551 IEEE80211_HW_SUPPORTS_PS |
Sujitheeee1322009-03-10 10:39:53 +05301552 IEEE80211_HW_PS_NULLFUNC_STACK |
1553 IEEE80211_HW_SPECTRUM_MGMT;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301554
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001555 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001556 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
1557
Sujith9c84b792008-10-29 10:17:13 +05301558 hw->wiphy->interface_modes =
1559 BIT(NL80211_IFTYPE_AP) |
1560 BIT(NL80211_IFTYPE_STATION) |
Pat Erley9cb54122009-03-20 22:59:59 -04001561 BIT(NL80211_IFTYPE_ADHOC) |
1562 BIT(NL80211_IFTYPE_MESH_POINT);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301563
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301564 hw->queues = 4;
Sujithe63835b2008-11-18 09:07:53 +05301565 hw->max_rates = 4;
Sujith171387e2009-02-17 15:36:25 +05301566 hw->channel_change_time = 5000;
Jouni Malinen465ca842009-03-03 19:23:34 +02001567 hw->max_listen_interval = 10;
Luis R. Rodriguezdd190182009-07-14 20:13:56 -04001568 /* Hardware supports 10 but we use 4 */
1569 hw->max_rate_tries = 4;
Sujith528f0c62008-10-29 10:14:26 +05301570 hw->sta_data_size = sizeof(struct ath_node);
Sujith17d79042009-02-09 13:27:03 +05301571 hw->vif_data_size = sizeof(struct ath_vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301572
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301573 hw->rate_control_algorithm = "ath9k_rate_control";
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301574
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001575 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
1576 &sc->sbands[IEEE80211_BAND_2GHZ];
1577 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
1578 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
1579 &sc->sbands[IEEE80211_BAND_5GHZ];
1580}
1581
Luis R. Rodriguez1e40bcf2009-08-03 12:24:47 -07001582/* Device driver core initialization */
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301583int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid)
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001584{
1585 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001586 struct ath_hw *ah;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001587 int error = 0, i;
Bob Copeland3a702e42009-03-30 22:30:29 -04001588 struct ath_regulatory *reg;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001589
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001590 dev_dbg(sc->dev, "Attach ATH hw\n");
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001591
Vasanthakumar Thiagarajanaeac3552009-09-09 15:25:49 +05301592 error = ath_init_softc(devid, sc, subsysid);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001593 if (error != 0)
1594 return error;
1595
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001596 ah = sc->sc_ah;
1597
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001598 /* get mac address from hardware and set in mac80211 */
1599
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001600 SET_IEEE80211_PERM_ADDR(hw, ah->macaddr);
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001601
1602 ath_set_hw_capab(sc, hw);
1603
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001604 error = ath_regd_init(&sc->common.regulatory, sc->hw->wiphy,
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001605 ath9k_reg_notifier);
1606 if (error)
1607 return error;
1608
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001609 reg = &sc->common.regulatory;
Luis R. Rodriguezc26c2e52009-05-19 18:27:11 -04001610
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001611 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Sujitheb2599c2009-01-23 11:20:44 +05301612 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001613 if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
Sujitheb2599c2009-01-23 11:20:44 +05301614 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Sujith9c84b792008-10-29 10:17:13 +05301615 }
1616
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301617 /* initialize tx/rx engine */
1618 error = ath_tx_init(sc, ATH_TXBUF);
1619 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301620 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301621
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301622 error = ath_rx_init(sc, ATH_RXBUF);
1623 if (error != 0)
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301624 goto error_attach;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301625
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001626 INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
Jouni Malinenf98c3bd2009-03-03 19:23:39 +02001627 INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
1628 sc->wiphy_scheduler_int = msecs_to_jiffies(500);
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001629
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301630 error = ieee80211_register_hw(hw);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301631
Bob Copeland3a702e42009-03-30 22:30:29 -04001632 if (!ath_is_world_regd(reg)) {
Bob Copelandc02cf372009-03-30 22:30:28 -04001633 error = regulatory_hint(hw->wiphy, reg->alpha2);
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05001634 if (error)
1635 goto error_attach;
1636 }
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001637
Senthil Balasubramaniandb93e7b2008-11-13 18:01:08 +05301638 /* Initialize LED control */
1639 ath_init_leds(sc);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301640
Johannes Berg3b319aa2009-06-13 14:50:26 +05301641 ath_start_rfkill_poll(sc);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001642
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301643 return 0;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301644
1645error_attach:
1646 /* cleanup tx queues */
1647 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1648 if (ATH_TXQ_SETUP(sc, i))
1649 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1650
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001651 ath9k_hw_detach(ah);
1652 ath9k_exit_debug(ah);
Luis R. Rodriguez3ce1b1a2009-08-03 12:24:53 -07001653 sc->sc_ah = NULL;
Vasanthakumar Thiagarajan40b130a2009-02-16 13:55:07 +05301654
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +05301655 return error;
1656}
1657
Sujithff37e332008-11-24 12:07:55 +05301658int ath_reset(struct ath_softc *sc, bool retry_tx)
1659{
Sujithcbe61d82009-02-09 13:27:12 +05301660 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -08001661 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001662 int r;
Sujithff37e332008-11-24 12:07:55 +05301663
1664 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +05301665 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +05301666 ath_stoprecv(sc);
1667 ath_flushrecv(sc);
1668
1669 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +05301670 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001671 if (r)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001672 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301673 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +05301674 spin_unlock_bh(&sc->sc_resetlock);
1675
1676 if (ath_startrecv(sc) != 0)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001677 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +05301678
1679 /*
1680 * We may be doing a reset in response to a request
1681 * that changes the channel so update any state that
1682 * might change as a result.
1683 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001684 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301685
1686 ath_update_txpow(sc);
1687
1688 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001689 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +05301690
Sujith17d79042009-02-09 13:27:03 +05301691 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301692
1693 if (retry_tx) {
1694 int i;
1695 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1696 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +05301697 spin_lock_bh(&sc->tx.txq[i].axq_lock);
1698 ath_txq_schedule(sc, &sc->tx.txq[i]);
1699 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +05301700 }
1701 }
1702 }
1703
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001704 return r;
Sujithff37e332008-11-24 12:07:55 +05301705}
1706
1707/*
1708 * This function will allocate both the DMA descriptor structure, and the
1709 * buffers it contains. These are used to contain the descriptors used
1710 * by the system.
1711*/
1712int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
1713 struct list_head *head, const char *name,
1714 int nbuf, int ndesc)
1715{
1716#define DS2PHYS(_dd, _ds) \
1717 ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
1718#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
1719#define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
1720
1721 struct ath_desc *ds;
1722 struct ath_buf *bf;
1723 int i, bsize, error;
1724
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001725 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Sujith04bd46382008-11-28 22:18:05 +05301726 name, nbuf, ndesc);
Sujithff37e332008-11-24 12:07:55 +05301727
Senthil Balasubramanianb03a9db2009-03-06 11:24:09 +05301728 INIT_LIST_HEAD(head);
Sujithff37e332008-11-24 12:07:55 +05301729 /* ath_desc must be a multiple of DWORDs */
1730 if ((sizeof(struct ath_desc) % 4) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001731 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
Sujithff37e332008-11-24 12:07:55 +05301732 ASSERT((sizeof(struct ath_desc) % 4) == 0);
1733 error = -ENOMEM;
1734 goto fail;
1735 }
1736
Sujithff37e332008-11-24 12:07:55 +05301737 dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
1738
1739 /*
1740 * Need additional DMA memory because we can't use
1741 * descriptors that cross the 4K page boundary. Assume
1742 * one skipped descriptor per 4K page.
1743 */
Sujith2660b812009-02-09 13:27:26 +05301744 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
Sujithff37e332008-11-24 12:07:55 +05301745 u32 ndesc_skipped =
1746 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
1747 u32 dma_len;
1748
1749 while (ndesc_skipped) {
1750 dma_len = ndesc_skipped * sizeof(struct ath_desc);
1751 dd->dd_desc_len += dma_len;
1752
1753 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
1754 };
1755 }
1756
1757 /* allocate descriptors */
Gabor Juhos7da3c552009-01-14 20:17:03 +01001758 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301759 &dd->dd_desc_paddr, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301760 if (dd->dd_desc == NULL) {
1761 error = -ENOMEM;
1762 goto fail;
1763 }
1764 ds = dd->dd_desc;
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07001765 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Sujithae459af2009-03-30 15:28:40 +05301766 name, ds, (u32) dd->dd_desc_len,
Sujithff37e332008-11-24 12:07:55 +05301767 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
1768
1769 /* allocate buffers */
1770 bsize = sizeof(struct ath_buf) * nbuf;
Senthil Balasubramanianf0e6ce12009-03-06 11:24:08 +05301771 bf = kzalloc(bsize, GFP_KERNEL);
Sujithff37e332008-11-24 12:07:55 +05301772 if (bf == NULL) {
1773 error = -ENOMEM;
1774 goto fail2;
1775 }
Sujithff37e332008-11-24 12:07:55 +05301776 dd->dd_bufptr = bf;
1777
Sujithff37e332008-11-24 12:07:55 +05301778 for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
1779 bf->bf_desc = ds;
1780 bf->bf_daddr = DS2PHYS(dd, ds);
1781
Sujith2660b812009-02-09 13:27:26 +05301782 if (!(sc->sc_ah->caps.hw_caps &
Sujithff37e332008-11-24 12:07:55 +05301783 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
1784 /*
1785 * Skip descriptor addresses which can cause 4KB
1786 * boundary crossing (addr + length) with a 32 dword
1787 * descriptor fetch.
1788 */
1789 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
1790 ASSERT((caddr_t) bf->bf_desc <
1791 ((caddr_t) dd->dd_desc +
1792 dd->dd_desc_len));
1793
1794 ds += ndesc;
1795 bf->bf_desc = ds;
1796 bf->bf_daddr = DS2PHYS(dd, ds);
1797 }
1798 }
1799 list_add_tail(&bf->list, head);
1800 }
1801 return 0;
1802fail2:
Gabor Juhos7da3c552009-01-14 20:17:03 +01001803 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1804 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05301805fail:
1806 memset(dd, 0, sizeof(*dd));
1807 return error;
1808#undef ATH_DESC_4KB_BOUND_CHECK
1809#undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
1810#undef DS2PHYS
1811}
1812
1813void ath_descdma_cleanup(struct ath_softc *sc,
1814 struct ath_descdma *dd,
1815 struct list_head *head)
1816{
Gabor Juhos7da3c552009-01-14 20:17:03 +01001817 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
1818 dd->dd_desc_paddr);
Sujithff37e332008-11-24 12:07:55 +05301819
1820 INIT_LIST_HEAD(head);
1821 kfree(dd->dd_bufptr);
1822 memset(dd, 0, sizeof(*dd));
1823}
1824
1825int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
1826{
1827 int qnum;
1828
1829 switch (queue) {
1830 case 0:
Sujithb77f4832008-12-07 21:44:03 +05301831 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301832 break;
1833 case 1:
Sujithb77f4832008-12-07 21:44:03 +05301834 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301835 break;
1836 case 2:
Sujithb77f4832008-12-07 21:44:03 +05301837 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301838 break;
1839 case 3:
Sujithb77f4832008-12-07 21:44:03 +05301840 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301841 break;
1842 default:
Sujithb77f4832008-12-07 21:44:03 +05301843 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301844 break;
1845 }
1846
1847 return qnum;
1848}
1849
1850int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1851{
1852 int qnum;
1853
1854 switch (queue) {
1855 case ATH9K_WME_AC_VO:
1856 qnum = 0;
1857 break;
1858 case ATH9K_WME_AC_VI:
1859 qnum = 1;
1860 break;
1861 case ATH9K_WME_AC_BE:
1862 qnum = 2;
1863 break;
1864 case ATH9K_WME_AC_BK:
1865 qnum = 3;
1866 break;
1867 default:
1868 qnum = -1;
1869 break;
1870 }
1871
1872 return qnum;
1873}
1874
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001875/* XXX: Remove me once we don't depend on ath9k_channel for all
1876 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001877void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1878 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001879{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001880 struct ieee80211_channel *chan = hw->conf.channel;
1881 struct ieee80211_conf *conf = &hw->conf;
1882
1883 ichan->channel = chan->center_freq;
1884 ichan->chan = chan;
1885
1886 if (chan->band == IEEE80211_BAND_2GHZ) {
1887 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05301888 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001889 } else {
1890 ichan->chanmode = CHANNEL_A;
1891 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1892 }
1893
1894 sc->tx_chan_width = ATH9K_HT_MACMODE_20;
1895
1896 if (conf_is_ht(conf)) {
1897 if (conf_is_ht40(conf))
1898 sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
1899
1900 ichan->chanmode = ath_get_extchanmode(sc, chan,
1901 conf->channel_type);
1902 }
1903}
1904
Sujithff37e332008-11-24 12:07:55 +05301905/**********************/
1906/* mac80211 callbacks */
1907/**********************/
1908
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001909static int ath9k_start(struct ieee80211_hw *hw)
1910{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001911 struct ath_wiphy *aphy = hw->priv;
1912 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001913 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001914 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301915 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301916 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001917
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001918 DPRINTF(ah, ATH_DBG_CONFIG, "Starting driver with "
Sujith04bd46382008-11-28 22:18:05 +05301919 "initial channel: %d MHz\n", curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001920
Sujith141b38b2009-02-04 08:10:07 +05301921 mutex_lock(&sc->mutex);
1922
Jouni Malinen9580a222009-03-03 19:23:33 +02001923 if (ath9k_wiphy_started(sc)) {
1924 if (sc->chan_idx == curchan->hw_value) {
1925 /*
1926 * Already on the operational channel, the new wiphy
1927 * can be marked active.
1928 */
1929 aphy->state = ATH_WIPHY_ACTIVE;
1930 ieee80211_wake_queues(hw);
1931 } else {
1932 /*
1933 * Another wiphy is on another channel, start the new
1934 * wiphy in paused state.
1935 */
1936 aphy->state = ATH_WIPHY_PAUSED;
1937 ieee80211_stop_queues(hw);
1938 }
1939 mutex_unlock(&sc->mutex);
1940 return 0;
1941 }
1942 aphy->state = ATH_WIPHY_ACTIVE;
1943
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001944 /* setup initial channel */
1945
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301946 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001947
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301948 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001949
Sujithff37e332008-11-24 12:07:55 +05301950 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001951 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05301952
1953 /*
1954 * The basic interface to setting the hardware in a good
1955 * state is ``reset''. On return the hardware is known to
1956 * be powered up and with interrupts disabled. This must
1957 * be followed by initialization of the appropriate bits
1958 * and then setup of the interrupt mask.
1959 */
1960 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001961 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001962 if (r) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001963 DPRINTF(ah, ATH_DBG_FATAL,
Vasanthakumar Thiagarajan6b457842009-05-15 18:59:20 +05301964 "Unable to reset hardware; reset status %d "
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001965 "(freq %u MHz)\n", r,
1966 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05301967 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05301968 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969 }
Sujithff37e332008-11-24 12:07:55 +05301970 spin_unlock_bh(&sc->sc_resetlock);
1971
1972 /*
1973 * This is needed only to setup initial state
1974 * but it's best done after a reset.
1975 */
1976 ath_update_txpow(sc);
1977
1978 /*
1979 * Setup the hardware after reset:
1980 * The receive engine is set going.
1981 * Frame transmit is handled entirely
1982 * in the frame output path; there's nothing to do
1983 * here except setup the interrupt mask.
1984 */
1985 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001986 DPRINTF(ah, ATH_DBG_FATAL, "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05301987 r = -EIO;
1988 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05301989 }
1990
1991 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05301992 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05301993 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
1994 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
1995
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001996 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05301997 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05301998
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001999 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05302000 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05302001
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08002002 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05302003
2004 sc->sc_flags &= ~SC_OP_INVALID;
2005
2006 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05302007 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002008 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05302009
Jouni Malinenbce048d2009-03-03 19:23:28 +02002010 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002011
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002012 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04002013
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002014 if ((ah->btcoex_info.btcoex_scheme != ATH_BTCOEX_CFG_NONE) &&
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302015 !(sc->sc_flags & SC_OP_BTCOEX_ENABLED)) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002016 ath9k_hw_btcoex_init_weight(ah);
2017 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05302018
Vasanthakumar Thiagarajan7b6840a2009-09-07 17:46:49 +05302019 ath_pcie_aspm_disable(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002020 if (ah->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez2e202502009-09-09 01:18:09 -07002021 ath_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302022 }
2023
Sujith141b38b2009-02-04 08:10:07 +05302024mutex_unlock:
2025 mutex_unlock(&sc->mutex);
2026
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08002027 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002028}
2029
2030static int ath9k_tx(struct ieee80211_hw *hw,
2031 struct sk_buff *skb)
2032{
Jouni Malinen147583c2008-08-11 14:01:50 +03002033 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02002034 struct ath_wiphy *aphy = hw->priv;
2035 struct ath_softc *sc = aphy->sc;
Sujith528f0c62008-10-29 10:14:26 +05302036 struct ath_tx_control txctl;
2037 int hdrlen, padsize;
2038
Jouni Malinen8089cc42009-03-03 19:23:38 +02002039 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Jouni Malinenee166a02009-03-03 19:23:36 +02002040 printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
2041 "%d\n", wiphy_name(hw->wiphy), aphy->state);
2042 goto exit;
2043 }
2044
Gabor Juhos96148322009-07-24 17:27:21 +02002045 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03002046 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2047 /*
2048 * mac80211 does not set PM field for normal data frames, so we
2049 * need to update that based on the current PS mode.
2050 */
2051 if (ieee80211_is_data(hdr->frame_control) &&
2052 !ieee80211_is_nullfunc(hdr->frame_control) &&
2053 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002054 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Add PM=1 for a TX frame "
Jouni Malinendc8c4582009-05-19 17:01:42 +03002055 "while in PS mode\n");
2056 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
2057 }
2058 }
2059
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002060 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
2061 /*
2062 * We are using PS-Poll and mac80211 can request TX while in
2063 * power save mode. Need to wake up hardware for the TX to be
2064 * completed and if needed, also for RX of buffered frames.
2065 */
2066 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2067 ath9k_ps_wakeup(sc);
2068 ath9k_hw_setrxabort(sc->sc_ah, 0);
2069 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002070 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Sending PS-Poll to pick a "
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002071 "buffered frame\n");
2072 sc->sc_flags |= SC_OP_WAIT_FOR_PSPOLL_DATA;
2073 } else {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002074 DPRINTF(sc->sc_ah, ATH_DBG_PS, "Wake up to complete TX\n");
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002075 sc->sc_flags |= SC_OP_WAIT_FOR_TX_ACK;
2076 }
2077 /*
2078 * The actual restore operation will happen only after
2079 * the sc_flags bit is cleared. We are just dropping
2080 * the ps_usecount here.
2081 */
2082 ath9k_ps_restore(sc);
2083 }
2084
Sujith528f0c62008-10-29 10:14:26 +05302085 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03002086
2087 /*
2088 * As a temporary workaround, assign seq# here; this will likely need
2089 * to be cleaned up to work better with Beacon transmission and virtual
2090 * BSSes.
2091 */
2092 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2093 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2094 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05302095 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03002096 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05302097 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03002098 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002099
2100 /* Add the padding after the header if this is not already done */
2101 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
2102 if (hdrlen & 3) {
2103 padsize = hdrlen % 4;
2104 if (skb_headroom(skb) < padsize)
2105 return -1;
2106 skb_push(skb, padsize);
2107 memmove(skb->data, skb->data + padsize, hdrlen);
2108 }
2109
Sujith528f0c62008-10-29 10:14:26 +05302110 /* Check if a tx queue is available */
2111
2112 txctl.txq = ath_test_get_txq(sc, skb);
2113 if (!txctl.txq)
2114 goto exit;
2115
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002116 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002117
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002118 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002119 DPRINTF(sc->sc_ah, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05302120 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002121 }
2122
2123 return 0;
Sujith528f0c62008-10-29 10:14:26 +05302124exit:
2125 dev_kfree_skb_any(skb);
2126 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002127}
2128
2129static void ath9k_stop(struct ieee80211_hw *hw)
2130{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002131 struct ath_wiphy *aphy = hw->priv;
2132 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002133 struct ath_hw *ah = sc->sc_ah;
Sujith9c84b792008-10-29 10:17:13 +05302134
Sujith4c483812009-08-18 10:51:52 +05302135 mutex_lock(&sc->mutex);
2136
Jouni Malinen9580a222009-03-03 19:23:33 +02002137 aphy->state = ATH_WIPHY_INACTIVE;
2138
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07002139 cancel_delayed_work_sync(&sc->ath_led_blink_work);
2140 cancel_delayed_work_sync(&sc->tx_complete_work);
2141
2142 if (!sc->num_sec_wiphy) {
2143 cancel_delayed_work_sync(&sc->wiphy_work);
2144 cancel_work_sync(&sc->chan_work);
2145 }
2146
Sujith9c84b792008-10-29 10:17:13 +05302147 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002148 DPRINTF(ah, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05302149 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05302150 return;
2151 }
2152
Jouni Malinen9580a222009-03-03 19:23:33 +02002153 if (ath9k_wiphy_started(sc)) {
2154 mutex_unlock(&sc->mutex);
2155 return; /* another wiphy still in use */
2156 }
2157
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302158 if (sc->sc_flags & SC_OP_BTCOEX_ENABLED) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002159 ath9k_hw_btcoex_disable(ah);
2160 if (ah->btcoex_info.btcoex_scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez2e202502009-09-09 01:18:09 -07002161 ath_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05302162 }
2163
Sujithff37e332008-11-24 12:07:55 +05302164 /* make sure h/w will not generate any interrupt
2165 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002166 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05302167
2168 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05302169 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05302170 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002171 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05302172 } else
Sujithb77f4832008-12-07 21:44:03 +05302173 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05302174
Sujithff37e332008-11-24 12:07:55 +05302175 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002176 ath9k_hw_disable(ah);
2177 ath9k_hw_configpcipowersave(ah, 1, 1);
2178 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05302179
2180 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002181
Sujith141b38b2009-02-04 08:10:07 +05302182 mutex_unlock(&sc->mutex);
2183
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07002184 DPRINTF(ah, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002185}
2186
2187static int ath9k_add_interface(struct ieee80211_hw *hw,
2188 struct ieee80211_if_init_conf *conf)
2189{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002190 struct ath_wiphy *aphy = hw->priv;
2191 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302192 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08002193 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002194 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002195
Sujith141b38b2009-02-04 08:10:07 +05302196 mutex_lock(&sc->mutex);
2197
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002198 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
2199 sc->nvifs > 0) {
2200 ret = -ENOBUFS;
2201 goto out;
2202 }
2203
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002204 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002205 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08002206 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002207 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02002208 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02002209 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04002210 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002211 if (sc->nbcnvifs >= ATH_BCBUF) {
2212 ret = -ENOBUFS;
2213 goto out;
2214 }
Pat Erley9cb54122009-03-20 22:59:59 -04002215 ic_opmode = conf->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03002216 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002217 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002218 DPRINTF(sc->sc_ah, ATH_DBG_FATAL,
Sujith04bd46382008-11-28 22:18:05 +05302219 "Interface type %d not yet supported\n", conf->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002220 ret = -EOPNOTSUPP;
2221 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002222 }
2223
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002224 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002225
Sujith17d79042009-02-09 13:27:03 +05302226 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05302227 avp->av_opmode = ic_opmode;
2228 avp->av_bslot = -1;
2229
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002230 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02002231
2232 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
2233 ath9k_set_bssid_mask(hw);
2234
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002235 if (sc->nvifs > 1)
2236 goto out; /* skip global settings for secondary vif */
2237
Sujithb238e902009-03-03 10:16:56 +05302238 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05302239 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05302240 sc->sc_flags |= SC_OP_TSF_RESET;
2241 }
Sujith5640b082008-10-29 10:16:06 +05302242
Sujith5640b082008-10-29 10:16:06 +05302243 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05302244 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05302245
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302246 /*
2247 * Enable MIB interrupts when there are hardware phy counters.
2248 * Note we only do this (at the moment) for station mode.
2249 */
Sujith4af9cf42009-02-12 10:06:47 +05302250 if ((conf->type == NL80211_IFTYPE_STATION) ||
Pat Erley9cb54122009-03-20 22:59:59 -04002251 (conf->type == NL80211_IFTYPE_ADHOC) ||
2252 (conf->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05302253 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05302254 sc->imask |= ATH9K_INT_TSFOOR;
2255 }
2256
Sujith17d79042009-02-09 13:27:03 +05302257 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05302258
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +05302259 if (conf->type == NL80211_IFTYPE_AP ||
2260 conf->type == NL80211_IFTYPE_ADHOC ||
2261 conf->type == NL80211_IFTYPE_MONITOR)
Sujith415f7382009-04-13 21:56:46 +05302262 ath_start_ani(sc);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002263
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002264out:
Sujith141b38b2009-02-04 08:10:07 +05302265 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002266 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002267}
2268
2269static void ath9k_remove_interface(struct ieee80211_hw *hw,
2270 struct ieee80211_if_init_conf *conf)
2271{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002272 struct ath_wiphy *aphy = hw->priv;
2273 struct ath_softc *sc = aphy->sc;
Sujith17d79042009-02-09 13:27:03 +05302274 struct ath_vif *avp = (void *)conf->vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002275 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002276
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002277 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002278
Sujith141b38b2009-02-04 08:10:07 +05302279 mutex_lock(&sc->mutex);
2280
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07002281 /* Stop ANI */
Sujith17d79042009-02-09 13:27:03 +05302282 del_timer_sync(&sc->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002283
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002284 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04002285 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
2286 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
2287 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Sujithb77f4832008-12-07 21:44:03 +05302288 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002289 ath_beacon_return(sc, avp);
2290 }
2291
Sujith672840a2008-08-11 14:05:08 +05302292 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002293
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002294 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
2295 if (sc->beacon.bslot[i] == conf->vif) {
2296 printk(KERN_DEBUG "%s: vif had allocated beacon "
2297 "slot\n", __func__);
2298 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02002299 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02002300 }
2301 }
2302
Sujith17d79042009-02-09 13:27:03 +05302303 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05302304
2305 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002306}
2307
Johannes Berge8975582008-10-09 12:18:51 +02002308static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002309{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002310 struct ath_wiphy *aphy = hw->priv;
2311 struct ath_softc *sc = aphy->sc;
Johannes Berge8975582008-10-09 12:18:51 +02002312 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05302313 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002314 bool all_wiphys_idle = false, disable_radio = false;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002315
Sujithaa33de02008-12-18 11:40:16 +05302316 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302317
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002318 /* Leave this as the first check */
2319 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
2320
2321 spin_lock_bh(&sc->wiphy_lock);
2322 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
2323 spin_unlock_bh(&sc->wiphy_lock);
2324
2325 if (conf->flags & IEEE80211_CONF_IDLE){
2326 if (all_wiphys_idle)
2327 disable_radio = true;
2328 }
2329 else if (all_wiphys_idle) {
2330 ath_radio_enable(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002331 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002332 "not-idle: enabling radio\n");
2333 }
2334 }
2335
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302336 if (changed & IEEE80211_CONF_CHANGE_PS) {
2337 if (conf->flags & IEEE80211_CONF_PS) {
Vivek Natarajan8782b412009-03-30 14:17:00 +05302338 if (!(ah->caps.hw_caps &
2339 ATH9K_HW_CAP_AUTOSLEEP)) {
2340 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
2341 sc->imask |= ATH9K_INT_TIM_TIMER;
2342 ath9k_hw_set_interrupts(sc->sc_ah,
2343 sc->imask);
2344 }
2345 ath9k_hw_setrxabort(sc->sc_ah, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302346 }
Gabor Juhos96148322009-07-24 17:27:21 +02002347 sc->ps_enabled = true;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302348 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02002349 sc->ps_enabled = false;
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302350 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302351 if (!(ah->caps.hw_caps &
2352 ATH9K_HW_CAP_AUTOSLEEP)) {
2353 ath9k_hw_setrxabort(sc->sc_ah, 0);
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03002354 sc->sc_flags &= ~(SC_OP_WAIT_FOR_BEACON |
2355 SC_OP_WAIT_FOR_CAB |
2356 SC_OP_WAIT_FOR_PSPOLL_DATA |
2357 SC_OP_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05302358 if (sc->imask & ATH9K_INT_TIM_TIMER) {
2359 sc->imask &= ~ATH9K_INT_TIM_TIMER;
2360 ath9k_hw_set_interrupts(sc->sc_ah,
2361 sc->imask);
2362 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302363 }
2364 }
2365 }
2366
Johannes Berg47979382009-01-07 10:13:27 +01002367 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05302368 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002369 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002370
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002371 aphy->chan_idx = pos;
2372 aphy->chan_is_ht = conf_is_ht(conf);
2373
Jouni Malinen8089cc42009-03-03 19:23:38 +02002374 if (aphy->state == ATH_WIPHY_SCAN ||
2375 aphy->state == ATH_WIPHY_ACTIVE)
2376 ath9k_wiphy_pause_all_forced(sc, aphy);
2377 else {
2378 /*
2379 * Do not change operational channel based on a paused
2380 * wiphy changes.
2381 */
2382 goto skip_chan_change;
2383 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002384
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002385 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
Sujith04bd46382008-11-28 22:18:05 +05302386 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02002387
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08002388 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002389 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05302390
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08002391 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05302392
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02002393 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002394 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05302395 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05302396 return -EINVAL;
2397 }
Sujith094d05d2008-12-12 11:57:43 +05302398 }
Sujith86b89ee2008-08-07 10:54:57 +05302399
Jouni Malinen8089cc42009-03-03 19:23:38 +02002400skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07002401 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05302402 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002403
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002404 if (disable_radio) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002405 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04002406 ath_radio_disable(sc);
2407 }
2408
Sujithaa33de02008-12-18 11:40:16 +05302409 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05302410
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002411 return 0;
2412}
2413
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002414#define SUPPORTED_FILTERS \
2415 (FIF_PROMISC_IN_BSS | \
2416 FIF_ALLMULTI | \
2417 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04002418 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002419 FIF_OTHER_BSS | \
2420 FIF_BCN_PRBRESP_PROMISC | \
2421 FIF_FCSFAIL)
2422
Sujith7dcfdcd2008-08-11 14:03:13 +05302423/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002424static void ath9k_configure_filter(struct ieee80211_hw *hw,
2425 unsigned int changed_flags,
2426 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02002427 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002428{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002429 struct ath_wiphy *aphy = hw->priv;
2430 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05302431 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002432
2433 changed_flags &= SUPPORTED_FILTERS;
2434 *total_flags &= SUPPORTED_FILTERS;
2435
Sujithb77f4832008-12-07 21:44:03 +05302436 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002437 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302438 rfilt = ath_calcrxfilter(sc);
2439 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03002440 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05302441
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002442 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002443}
2444
2445static void ath9k_sta_notify(struct ieee80211_hw *hw,
2446 struct ieee80211_vif *vif,
2447 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02002448 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002449{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002450 struct ath_wiphy *aphy = hw->priv;
2451 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002452
2453 switch (cmd) {
2454 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05302455 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002456 break;
2457 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05302458 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002459 break;
2460 default:
2461 break;
2462 }
2463}
2464
Sujith141b38b2009-02-04 08:10:07 +05302465static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002466 const struct ieee80211_tx_queue_params *params)
2467{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002468 struct ath_wiphy *aphy = hw->priv;
2469 struct ath_softc *sc = aphy->sc;
Sujithea9880f2008-08-07 10:53:10 +05302470 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002471 int ret = 0, qnum;
2472
2473 if (queue >= WME_NUM_AC)
2474 return 0;
2475
Sujith141b38b2009-02-04 08:10:07 +05302476 mutex_lock(&sc->mutex);
2477
Sujith1ffb0612009-03-30 15:28:46 +05302478 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
2479
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002480 qi.tqi_aifs = params->aifs;
2481 qi.tqi_cwmin = params->cw_min;
2482 qi.tqi_cwmax = params->cw_max;
2483 qi.tqi_burstTime = params->txop;
2484 qnum = ath_get_hal_qnum(queue, sc);
2485
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002486 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Sujith04bd46382008-11-28 22:18:05 +05302487 "Configure tx [queue/halq] [%d/%d], "
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002488 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
Sujith04bd46382008-11-28 22:18:05 +05302489 queue, qnum, params->aifs, params->cw_min,
2490 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002491
2492 ret = ath_txq_update(sc, qnum, &qi);
2493 if (ret)
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002494 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002495
Sujith141b38b2009-02-04 08:10:07 +05302496 mutex_unlock(&sc->mutex);
2497
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002498 return ret;
2499}
2500
2501static int ath9k_set_key(struct ieee80211_hw *hw,
2502 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002503 struct ieee80211_vif *vif,
2504 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002505 struct ieee80211_key_conf *key)
2506{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002507 struct ath_wiphy *aphy = hw->priv;
2508 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002509 int ret = 0;
2510
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02002511 if (modparam_nohwcrypt)
2512 return -ENOSPC;
2513
Sujith141b38b2009-02-04 08:10:07 +05302514 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302515 ath9k_ps_wakeup(sc);
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002516 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002517
2518 switch (cmd) {
2519 case SET_KEY:
Jouni Malinen3f53dd62009-02-26 11:18:46 +02002520 ret = ath_key_config(sc, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02002521 if (ret >= 0) {
2522 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002523 /* push IV and Michael MIC generation to stack */
2524 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05302525 if (key->alg == ALG_TKIP)
2526 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02002527 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
2528 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02002529 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002530 }
2531 break;
2532 case DISABLE_KEY:
2533 ath_key_delete(sc, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002534 break;
2535 default:
2536 ret = -EINVAL;
2537 }
2538
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05302539 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05302540 mutex_unlock(&sc->mutex);
2541
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002542 return ret;
2543}
2544
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002545static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2546 struct ieee80211_vif *vif,
2547 struct ieee80211_bss_conf *bss_conf,
2548 u32 changed)
2549{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002550 struct ath_wiphy *aphy = hw->priv;
2551 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002552 struct ath_hw *ah = sc->sc_ah;
2553 struct ath_vif *avp = (void *)vif->drv_priv;
2554 u32 rfilt = 0;
2555 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002556
Sujith141b38b2009-02-04 08:10:07 +05302557 mutex_lock(&sc->mutex);
2558
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002559 /*
2560 * TODO: Need to decide which hw opmode to use for
2561 * multi-interface cases
2562 * XXX: This belongs into add_interface!
2563 */
2564 if (vif->type == NL80211_IFTYPE_AP &&
2565 ah->opmode != NL80211_IFTYPE_AP) {
2566 ah->opmode = NL80211_IFTYPE_STATION;
2567 ath9k_hw_setopmode(ah);
2568 memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
2569 sc->curaid = 0;
2570 ath9k_hw_write_associd(sc);
2571 /* Request full reset to get hw opmode changed properly */
2572 sc->sc_flags |= SC_OP_FULL_RESET;
2573 }
2574
2575 if ((changed & BSS_CHANGED_BSSID) &&
2576 !is_zero_ether_addr(bss_conf->bssid)) {
2577 switch (vif->type) {
2578 case NL80211_IFTYPE_STATION:
2579 case NL80211_IFTYPE_ADHOC:
2580 case NL80211_IFTYPE_MESH_POINT:
2581 /* Set BSSID */
2582 memcpy(sc->curbssid, bss_conf->bssid, ETH_ALEN);
2583 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
2584 sc->curaid = 0;
2585 ath9k_hw_write_associd(sc);
2586
2587 /* Set aggregation protection mode parameters */
2588 sc->config.ath_aggr_prot = 0;
2589
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002590 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG,
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002591 "RX filter 0x%x bssid %pM aid 0x%x\n",
2592 rfilt, sc->curbssid, sc->curaid);
2593
2594 /* need to reconfigure the beacon */
2595 sc->sc_flags &= ~SC_OP_BEACONS ;
2596
2597 break;
2598 default:
2599 break;
2600 }
2601 }
2602
2603 if ((vif->type == NL80211_IFTYPE_ADHOC) ||
2604 (vif->type == NL80211_IFTYPE_AP) ||
2605 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
2606 if ((changed & BSS_CHANGED_BEACON) ||
2607 (changed & BSS_CHANGED_BEACON_ENABLED &&
2608 bss_conf->enable_beacon)) {
2609 /*
2610 * Allocate and setup the beacon frame.
2611 *
2612 * Stop any previous beacon DMA. This may be
2613 * necessary, for example, when an ibss merge
2614 * causes reconfiguration; we may be called
2615 * with beacon transmission active.
2616 */
2617 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
2618
2619 error = ath_beacon_alloc(aphy, vif);
2620 if (!error)
2621 ath_beacon_config(sc, vif);
2622 }
2623 }
2624
2625 /* Check for WLAN_CAPABILITY_PRIVACY ? */
2626 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
2627 for (i = 0; i < IEEE80211_WEP_NKID; i++)
2628 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
2629 ath9k_hw_keysetmac(sc->sc_ah,
2630 (u16)i,
2631 sc->curbssid);
2632 }
2633
2634 /* Only legacy IBSS for now */
2635 if (vif->type == NL80211_IFTYPE_ADHOC)
2636 ath_update_chainmask(sc, 0);
2637
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002638 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002639 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002640 bss_conf->use_short_preamble);
2641 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05302642 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002643 else
Sujith672840a2008-08-11 14:05:08 +05302644 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002645 }
2646
2647 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002648 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002649 bss_conf->use_cts_prot);
2650 if (bss_conf->use_cts_prot &&
2651 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05302652 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002653 else
Sujith672840a2008-08-11 14:05:08 +05302654 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002655 }
2656
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002657 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002658 DPRINTF(sc->sc_ah, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002659 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05302660 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002661 }
Sujith141b38b2009-02-04 08:10:07 +05302662
Johannes Berg57c4d7b2009-04-23 16:10:04 +02002663 /*
2664 * The HW TSF has to be reset when the beacon interval changes.
2665 * We set the flag here, and ath_beacon_config_ap() would take this
2666 * into account when it gets called through the subsequent
2667 * config_interface() call - with IFCC_BEACON in the changed field.
2668 */
2669
2670 if (changed & BSS_CHANGED_BEACON_INT) {
2671 sc->sc_flags |= SC_OP_TSF_RESET;
2672 sc->beacon_interval = bss_conf->beacon_int;
2673 }
2674
Sujith141b38b2009-02-04 08:10:07 +05302675 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002676}
2677
2678static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
2679{
2680 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02002681 struct ath_wiphy *aphy = hw->priv;
2682 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002683
Sujith141b38b2009-02-04 08:10:07 +05302684 mutex_lock(&sc->mutex);
2685 tsf = ath9k_hw_gettsf64(sc->sc_ah);
2686 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002687
2688 return tsf;
2689}
2690
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002691static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
2692{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002693 struct ath_wiphy *aphy = hw->priv;
2694 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002695
Sujith141b38b2009-02-04 08:10:07 +05302696 mutex_lock(&sc->mutex);
2697 ath9k_hw_settsf64(sc->sc_ah, tsf);
2698 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002699}
2700
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002701static void ath9k_reset_tsf(struct ieee80211_hw *hw)
2702{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002703 struct ath_wiphy *aphy = hw->priv;
2704 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002705
Sujith141b38b2009-02-04 08:10:07 +05302706 mutex_lock(&sc->mutex);
2707 ath9k_hw_reset_tsf(sc->sc_ah);
2708 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002709}
2710
2711static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Sujith141b38b2009-02-04 08:10:07 +05302712 enum ieee80211_ampdu_mlme_action action,
2713 struct ieee80211_sta *sta,
2714 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002715{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002716 struct ath_wiphy *aphy = hw->priv;
2717 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002718 int ret = 0;
2719
2720 switch (action) {
2721 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05302722 if (!(sc->sc_flags & SC_OP_RXAGGR))
2723 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002724 break;
2725 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002726 break;
2727 case IEEE80211_AMPDU_TX_START:
Sujithf83da962009-07-23 15:32:37 +05302728 ath_tx_aggr_start(sc, sta, tid, ssn);
2729 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002730 break;
2731 case IEEE80211_AMPDU_TX_STOP:
Sujithf83da962009-07-23 15:32:37 +05302732 ath_tx_aggr_stop(sc, sta, tid);
Johannes Berg17741cd2008-09-11 00:02:02 +02002733 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002734 break;
Johannes Bergb1720232009-03-23 17:28:39 +01002735 case IEEE80211_AMPDU_TX_OPERATIONAL:
Sujith8469cde2008-10-29 10:19:28 +05302736 ath_tx_aggr_resume(sc, sta, tid);
2737 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002738 default:
Luis R. Rodriguez4d6b2282009-09-07 04:52:26 -07002739 DPRINTF(sc->sc_ah, ATH_DBG_FATAL, "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002740 }
2741
2742 return ret;
2743}
2744
Sujith0c98de62009-03-03 10:16:45 +05302745static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2746{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002747 struct ath_wiphy *aphy = hw->priv;
2748 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302749
Sujith3d832612009-08-21 12:00:28 +05302750 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002751 if (ath9k_wiphy_scanning(sc)) {
2752 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
2753 "same time\n");
2754 /*
2755 * Do not allow the concurrent scanning state for now. This
2756 * could be improved with scanning control moved into ath9k.
2757 */
Sujith3d832612009-08-21 12:00:28 +05302758 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002759 return;
2760 }
2761
2762 aphy->state = ATH_WIPHY_SCAN;
2763 ath9k_wiphy_pause_all_forced(sc, aphy);
2764
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302765 spin_lock_bh(&sc->ani_lock);
Sujith0c98de62009-03-03 10:16:45 +05302766 sc->sc_flags |= SC_OP_SCANNING;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302767 spin_unlock_bh(&sc->ani_lock);
Sujith3d832612009-08-21 12:00:28 +05302768 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302769}
2770
2771static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2772{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002773 struct ath_wiphy *aphy = hw->priv;
2774 struct ath_softc *sc = aphy->sc;
Sujith0c98de62009-03-03 10:16:45 +05302775
Sujith3d832612009-08-21 12:00:28 +05302776 mutex_lock(&sc->mutex);
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302777 spin_lock_bh(&sc->ani_lock);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002778 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05302779 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05302780 sc->sc_flags |= SC_OP_FULL_RESET;
Senthil Balasubramaniane5f09212009-06-24 18:56:41 +05302781 spin_unlock_bh(&sc->ani_lock);
Vivek Natarajand0bec342009-09-02 15:50:55 +05302782 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05302783 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302784}
2785
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002786struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002787 .tx = ath9k_tx,
2788 .start = ath9k_start,
2789 .stop = ath9k_stop,
2790 .add_interface = ath9k_add_interface,
2791 .remove_interface = ath9k_remove_interface,
2792 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002793 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002794 .sta_notify = ath9k_sta_notify,
2795 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002796 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002797 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002798 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002799 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002800 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002801 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05302802 .sw_scan_start = ath9k_sw_scan_start,
2803 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302804 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002805};
2806
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002807static struct {
2808 u32 version;
2809 const char * name;
2810} ath_mac_bb_names[] = {
2811 { AR_SREV_VERSION_5416_PCI, "5416" },
2812 { AR_SREV_VERSION_5416_PCIE, "5418" },
2813 { AR_SREV_VERSION_9100, "9100" },
2814 { AR_SREV_VERSION_9160, "9160" },
2815 { AR_SREV_VERSION_9280, "9280" },
Vivek Natarajanac88b6e2009-07-23 10:59:57 +05302816 { AR_SREV_VERSION_9285, "9285" },
2817 { AR_SREV_VERSION_9287, "9287" }
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002818};
2819
2820static struct {
2821 u16 version;
2822 const char * name;
2823} ath_rf_names[] = {
2824 { 0, "5133" },
2825 { AR_RAD5133_SREV_MAJOR, "5133" },
2826 { AR_RAD5122_SREV_MAJOR, "5122" },
2827 { AR_RAD2133_SREV_MAJOR, "2133" },
2828 { AR_RAD2122_SREV_MAJOR, "2122" }
2829};
2830
2831/*
2832 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
2833 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002834const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002835ath_mac_bb_name(u32 mac_bb_version)
2836{
2837 int i;
2838
2839 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
2840 if (ath_mac_bb_names[i].version == mac_bb_version) {
2841 return ath_mac_bb_names[i].name;
2842 }
2843 }
2844
2845 return "????";
2846}
2847
2848/*
2849 * Return the RF name. "????" is returned if the RF is unknown.
2850 */
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002851const char *
Benoit PAPILLAULT392dff82008-11-06 22:26:49 +01002852ath_rf_name(u16 rf_version)
2853{
2854 int i;
2855
2856 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
2857 if (ath_rf_names[i].version == rf_version) {
2858 return ath_rf_names[i].name;
2859 }
2860 }
2861
2862 return "????";
2863}
2864
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002865static int __init ath9k_init(void)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002866{
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302867 int error;
2868
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302869 /* Register rate control algorithm */
2870 error = ath_rate_control_register();
2871 if (error != 0) {
2872 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08002873 "ath9k: Unable to register rate control "
2874 "algorithm: %d\n",
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302875 error);
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002876 goto err_out;
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302877 }
2878
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002879 error = ath9k_debug_create_root();
2880 if (error) {
2881 printk(KERN_ERR
2882 "ath9k: Unable to create debugfs root: %d\n",
2883 error);
2884 goto err_rate_unregister;
2885 }
2886
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002887 error = ath_pci_init();
2888 if (error < 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002889 printk(KERN_ERR
Luis R. Rodriguezb51bb3c2009-01-26 07:30:03 -08002890 "ath9k: No PCI devices found, driver not installed.\n");
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002891 error = -ENODEV;
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002892 goto err_remove_root;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002893 }
2894
Gabor Juhos09329d32009-01-14 20:17:07 +01002895 error = ath_ahb_init();
2896 if (error < 0) {
2897 error = -ENODEV;
2898 goto err_pci_exit;
2899 }
2900
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002901 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002902
Gabor Juhos09329d32009-01-14 20:17:07 +01002903 err_pci_exit:
2904 ath_pci_exit();
2905
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002906 err_remove_root:
2907 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002908 err_rate_unregister:
Vasanthakumar Thiagarajanca8a8562008-12-16 12:37:38 +05302909 ath_rate_control_unregister();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002910 err_out:
2911 return error;
2912}
2913module_init(ath9k_init);
2914
2915static void __exit ath9k_exit(void)
2916{
Gabor Juhos09329d32009-01-14 20:17:07 +01002917 ath_ahb_exit();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002918 ath_pci_exit();
Gabor Juhos19d8bc22009-03-05 16:55:18 +01002919 ath9k_debug_remove_root();
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002920 ath_rate_control_unregister();
Sujith04bd46382008-11-28 22:18:05 +05302921 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002922}
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002923module_exit(ath9k_exit);