blob: 974de2056b4a0e9a043f194b954711c5c85e2673 [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. Rodriguezce111ba2008-12-23 15:58:39 -080021static void ath_cache_conf_rate(struct ath_softc *sc,
22 struct ieee80211_conf *conf)
Sujithff37e332008-11-24 12:07:55 +053023{
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080024 switch (conf->channel->band) {
25 case IEEE80211_BAND_2GHZ:
26 if (conf_is_ht20(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010027 sc->cur_rate_mode = ATH9K_MODE_11NG_HT20;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080028 else if (conf_is_ht40_minus(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010029 sc->cur_rate_mode = ATH9K_MODE_11NG_HT40MINUS;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080030 else if (conf_is_ht40_plus(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010031 sc->cur_rate_mode = ATH9K_MODE_11NG_HT40PLUS;
Luis R. Rodriguez96742252008-12-23 15:58:38 -080032 else
Felix Fietkau545750d2009-11-23 22:21:01 +010033 sc->cur_rate_mode = ATH9K_MODE_11G;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080034 break;
35 case IEEE80211_BAND_5GHZ:
36 if (conf_is_ht20(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010037 sc->cur_rate_mode = ATH9K_MODE_11NA_HT20;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080038 else if (conf_is_ht40_minus(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010039 sc->cur_rate_mode = ATH9K_MODE_11NA_HT40MINUS;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080040 else if (conf_is_ht40_plus(conf))
Felix Fietkau545750d2009-11-23 22:21:01 +010041 sc->cur_rate_mode = ATH9K_MODE_11NA_HT40PLUS;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080042 else
Felix Fietkau545750d2009-11-23 22:21:01 +010043 sc->cur_rate_mode = ATH9K_MODE_11A;
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080044 break;
45 default:
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -080046 BUG_ON(1);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -080047 break;
48 }
Sujithff37e332008-11-24 12:07:55 +053049}
50
51static void ath_update_txpow(struct ath_softc *sc)
52{
Sujithcbe61d82009-02-09 13:27:12 +053053 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +053054 u32 txpow;
55
Sujith17d79042009-02-09 13:27:03 +053056 if (sc->curtxpow != sc->config.txpowlimit) {
57 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
Sujithff37e332008-11-24 12:07:55 +053058 /* read back in case value is clamped */
59 ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
Sujith17d79042009-02-09 13:27:03 +053060 sc->curtxpow = txpow;
Sujithff37e332008-11-24 12:07:55 +053061 }
62}
63
64static u8 parse_mpdudensity(u8 mpdudensity)
65{
66 /*
67 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
68 * 0 for no restriction
69 * 1 for 1/4 us
70 * 2 for 1/2 us
71 * 3 for 1 us
72 * 4 for 2 us
73 * 5 for 4 us
74 * 6 for 8 us
75 * 7 for 16 us
76 */
77 switch (mpdudensity) {
78 case 0:
79 return 0;
80 case 1:
81 case 2:
82 case 3:
83 /* Our lower layer calculations limit our precision to
84 1 microsecond */
85 return 1;
86 case 4:
87 return 2;
88 case 5:
89 return 4;
90 case 6:
91 return 8;
92 case 7:
93 return 16;
94 default:
95 return 0;
96 }
97}
98
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +053099static struct ath9k_channel *ath_get_curchannel(struct ath_softc *sc,
100 struct ieee80211_hw *hw)
101{
102 struct ieee80211_channel *curchan = hw->conf.channel;
103 struct ath9k_channel *channel;
104 u8 chan_idx;
105
106 chan_idx = curchan->hw_value;
107 channel = &sc->sc_ah->channels[chan_idx];
108 ath9k_update_ichannel(sc, hw, channel);
109 return channel;
110}
111
Sujith55624202010-01-08 10:36:02 +0530112bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700113{
114 unsigned long flags;
115 bool ret;
116
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700117 spin_lock_irqsave(&sc->sc_pm_lock, flags);
118 ret = ath9k_hw_setpower(sc->sc_ah, mode);
119 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
Luis R. Rodriguez8c77a562009-09-09 21:02:34 -0700120
121 return ret;
122}
123
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700124void ath9k_ps_wakeup(struct ath_softc *sc)
125{
126 unsigned long flags;
127
128 spin_lock_irqsave(&sc->sc_pm_lock, flags);
129 if (++sc->ps_usecount != 1)
130 goto unlock;
131
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700132 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700133
134 unlock:
135 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
136}
137
138void ath9k_ps_restore(struct ath_softc *sc)
139{
140 unsigned long flags;
141
142 spin_lock_irqsave(&sc->sc_pm_lock, flags);
143 if (--sc->ps_usecount != 0)
144 goto unlock;
145
146 if (sc->ps_enabled &&
Sujith1b04b932010-01-08 10:36:05 +0530147 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
148 PS_WAIT_FOR_CAB |
149 PS_WAIT_FOR_PSPOLL_DATA |
150 PS_WAIT_FOR_TX_ACK)))
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700151 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
Luis R. Rodrigueza91d75a2009-09-09 20:29:18 -0700152
153 unlock:
154 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
155}
156
Sujithff37e332008-11-24 12:07:55 +0530157/*
158 * Set/change channels. If the channel is really being changed, it's done
159 * by reseting the chip. To accomplish this we must first cleanup any pending
160 * DMA, then restart stuff.
161*/
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200162int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
163 struct ath9k_channel *hchan)
Sujithff37e332008-11-24 12:07:55 +0530164{
Sujithcbe61d82009-02-09 13:27:12 +0530165 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700166 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700167 struct ieee80211_conf *conf = &common->hw->conf;
Sujithff37e332008-11-24 12:07:55 +0530168 bool fastcc = true, stopped;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800169 struct ieee80211_channel *channel = hw->conf.channel;
170 int r;
Sujithff37e332008-11-24 12:07:55 +0530171
172 if (sc->sc_flags & SC_OP_INVALID)
173 return -EIO;
174
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530175 ath9k_ps_wakeup(sc);
176
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800177 /*
178 * This is only performed if the channel settings have
179 * actually changed.
180 *
181 * To switch channels clear any pending DMA operations;
182 * wait long enough for the RX fifo to drain, reset the
183 * hardware at the new frequency, and then re-enable
184 * the relevant bits of the h/w.
185 */
186 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530187 ath_drain_all_txq(sc, false);
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800188 stopped = ath_stoprecv(sc);
Sujithff37e332008-11-24 12:07:55 +0530189
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800190 /* XXX: do not flush receive queue here. We don't want
191 * to flush data frames already in queue because of
192 * changing channel. */
Sujithff37e332008-11-24 12:07:55 +0530193
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800194 if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
195 fastcc = false;
Sujithff37e332008-11-24 12:07:55 +0530196
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700197 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700198 "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700199 sc->sc_ah->curchan->channel,
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -0700200 channel->center_freq, conf_is_ht40(conf));
Sujith99405f92008-11-24 12:08:35 +0530201
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800202 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800203
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800204 r = ath9k_hw_reset(ah, hchan, fastcc);
205 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700206 ath_print(common, ATH_DBG_FATAL,
207 "Unable to reset channel (%u Mhz) "
208 "reset status %d\n",
209 channel->center_freq, r);
Sujithff37e332008-11-24 12:07:55 +0530210 spin_unlock_bh(&sc->sc_resetlock);
Gabor Juhos39892792009-06-15 17:49:09 +0200211 goto ps_restore;
Sujithff37e332008-11-24 12:07:55 +0530212 }
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800213 spin_unlock_bh(&sc->sc_resetlock);
214
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800215 sc->sc_flags &= ~SC_OP_FULL_RESET;
216
217 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700218 ath_print(common, ATH_DBG_FATAL,
219 "Unable to restart recv logic\n");
Gabor Juhos39892792009-06-15 17:49:09 +0200220 r = -EIO;
221 goto ps_restore;
Luis R. Rodriguezc0d7c7a2008-12-23 15:58:50 -0800222 }
223
224 ath_cache_conf_rate(sc, &hw->conf);
225 ath_update_txpow(sc);
Sujith17d79042009-02-09 13:27:03 +0530226 ath9k_hw_set_interrupts(ah, sc->imask);
Gabor Juhos39892792009-06-15 17:49:09 +0200227
228 ps_restore:
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530229 ath9k_ps_restore(sc);
Gabor Juhos39892792009-06-15 17:49:09 +0200230 return r;
Sujithff37e332008-11-24 12:07:55 +0530231}
232
233/*
234 * This routine performs the periodic noise floor calibration function
235 * that is used to adjust and optimize the chip performance. This
236 * takes environmental changes (location, temperature) into account.
237 * When the task is complete, it reschedules itself depending on the
238 * appropriate interval that was calculated.
239 */
Sujith55624202010-01-08 10:36:02 +0530240void ath_ani_calibrate(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530241{
Sujith20977d32009-02-20 15:13:28 +0530242 struct ath_softc *sc = (struct ath_softc *)data;
243 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700244 struct ath_common *common = ath9k_hw_common(ah);
Sujithff37e332008-11-24 12:07:55 +0530245 bool longcal = false;
246 bool shortcal = false;
247 bool aniflag = false;
248 unsigned int timestamp = jiffies_to_msecs(jiffies);
Sujith20977d32009-02-20 15:13:28 +0530249 u32 cal_interval, short_cal_interval;
Sujithff37e332008-11-24 12:07:55 +0530250
Sujith20977d32009-02-20 15:13:28 +0530251 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
252 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
Sujithff37e332008-11-24 12:07:55 +0530253
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300254 /* Only calibrate if awake */
255 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
256 goto set_timer;
257
258 ath9k_ps_wakeup(sc);
259
Sujithff37e332008-11-24 12:07:55 +0530260 /* Long calibration runs independently of short calibration. */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800261 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530262 longcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700263 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800264 common->ani.longcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530265 }
266
Sujith17d79042009-02-09 13:27:03 +0530267 /* Short calibration applies only while caldone is false */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800268 if (!common->ani.caldone) {
269 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
Sujithff37e332008-11-24 12:07:55 +0530270 shortcal = true;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700271 ath_print(common, ATH_DBG_ANI,
272 "shortcal @%lu\n", jiffies);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800273 common->ani.shortcal_timer = timestamp;
274 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530275 }
276 } else {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800277 if ((timestamp - common->ani.resetcal_timer) >=
Sujithff37e332008-11-24 12:07:55 +0530278 ATH_RESTART_CALINTERVAL) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800279 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
280 if (common->ani.caldone)
281 common->ani.resetcal_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530282 }
283 }
284
285 /* Verify whether we must check ANI */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800286 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
Sujithff37e332008-11-24 12:07:55 +0530287 aniflag = true;
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800288 common->ani.checkani_timer = timestamp;
Sujithff37e332008-11-24 12:07:55 +0530289 }
290
291 /* Skip all processing if there's nothing to do. */
292 if (longcal || shortcal || aniflag) {
293 /* Call ANI routine if necessary */
294 if (aniflag)
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530295 ath9k_hw_ani_monitor(ah, ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530296
297 /* Perform calibration if necessary */
298 if (longcal || shortcal) {
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800299 common->ani.caldone =
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700300 ath9k_hw_calibrate(ah,
301 ah->curchan,
302 common->rx_chainmask,
303 longcal);
Sujithff37e332008-11-24 12:07:55 +0530304
Sujith379f0442009-04-13 21:56:48 +0530305 if (longcal)
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800306 common->ani.noise_floor = ath9k_hw_getchan_noise(ah,
Sujith379f0442009-04-13 21:56:48 +0530307 ah->curchan);
Sujithff37e332008-11-24 12:07:55 +0530308
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700309 ath_print(common, ATH_DBG_ANI,
310 " calibrate chan %u/%x nf: %d\n",
311 ah->curchan->channel,
312 ah->curchan->channelFlags,
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800313 common->ani.noise_floor);
Sujithff37e332008-11-24 12:07:55 +0530314 }
315 }
316
Jouni Malinen1ffc1c62009-05-19 17:01:39 +0300317 ath9k_ps_restore(sc);
318
Sujith20977d32009-02-20 15:13:28 +0530319set_timer:
Sujithff37e332008-11-24 12:07:55 +0530320 /*
321 * Set timer interval based on previous results.
322 * The interval must be the shortest necessary to satisfy ANI,
323 * short calibration and long calibration.
324 */
Sujithaac92072008-12-02 18:37:54 +0530325 cal_interval = ATH_LONG_CALINTERVAL;
Sujith2660b812009-02-09 13:27:26 +0530326 if (sc->sc_ah->config.enable_ani)
Sujithaac92072008-12-02 18:37:54 +0530327 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800328 if (!common->ani.caldone)
Sujith20977d32009-02-20 15:13:28 +0530329 cal_interval = min(cal_interval, (u32)short_cal_interval);
Sujithff37e332008-11-24 12:07:55 +0530330
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800331 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
Sujithff37e332008-11-24 12:07:55 +0530332}
333
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800334static void ath_start_ani(struct ath_common *common)
Sujith415f7382009-04-13 21:56:46 +0530335{
336 unsigned long timestamp = jiffies_to_msecs(jiffies);
337
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800338 common->ani.longcal_timer = timestamp;
339 common->ani.shortcal_timer = timestamp;
340 common->ani.checkani_timer = timestamp;
Sujith415f7382009-04-13 21:56:46 +0530341
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800342 mod_timer(&common->ani.timer,
Sujith415f7382009-04-13 21:56:46 +0530343 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
344}
345
Sujithff37e332008-11-24 12:07:55 +0530346/*
347 * Update tx/rx chainmask. For legacy association,
348 * hard code chainmask to 1x1, for 11n association, use
Vasanthakumar Thiagarajanc97c92d2009-01-02 15:35:46 +0530349 * the chainmask configuration, for bt coexistence, use
350 * the chainmask configuration even in legacy mode.
Sujithff37e332008-11-24 12:07:55 +0530351 */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +0200352void ath_update_chainmask(struct ath_softc *sc, int is_ht)
Sujithff37e332008-11-24 12:07:55 +0530353{
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700354 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700355 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700356
Sujith3d832612009-08-21 12:00:28 +0530357 if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700358 (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700359 common->tx_chainmask = ah->caps.tx_chainmask;
360 common->rx_chainmask = ah->caps.rx_chainmask;
Sujithff37e332008-11-24 12:07:55 +0530361 } else {
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700362 common->tx_chainmask = 1;
363 common->rx_chainmask = 1;
Sujithff37e332008-11-24 12:07:55 +0530364 }
365
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700366 ath_print(common, ATH_DBG_CONFIG,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700367 "tx chmask: %d, rx chmask: %d\n",
Luis R. Rodriguez43c27612009-09-13 21:07:07 -0700368 common->tx_chainmask,
369 common->rx_chainmask);
Sujithff37e332008-11-24 12:07:55 +0530370}
371
372static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
373{
374 struct ath_node *an;
375
376 an = (struct ath_node *)sta->drv_priv;
377
Sujith87792ef2009-03-30 15:28:48 +0530378 if (sc->sc_flags & SC_OP_TXAGGR) {
Sujithff37e332008-11-24 12:07:55 +0530379 ath_tx_node_init(sc, an);
Sujith9e98ac62009-07-23 15:32:34 +0530380 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
Sujith87792ef2009-03-30 15:28:48 +0530381 sta->ht_cap.ampdu_factor);
382 an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
Senthil Balasubramaniana59b5a52009-07-14 20:17:07 -0400383 an->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith87792ef2009-03-30 15:28:48 +0530384 }
Sujithff37e332008-11-24 12:07:55 +0530385}
386
387static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
388{
389 struct ath_node *an = (struct ath_node *)sta->drv_priv;
390
391 if (sc->sc_flags & SC_OP_TXAGGR)
392 ath_tx_node_cleanup(sc, an);
393}
394
Sujith55624202010-01-08 10:36:02 +0530395void ath9k_tasklet(unsigned long data)
Sujithff37e332008-11-24 12:07:55 +0530396{
397 struct ath_softc *sc = (struct ath_softc *)data;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700398 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700399 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700400
Sujith17d79042009-02-09 13:27:03 +0530401 u32 status = sc->intrstatus;
Sujithff37e332008-11-24 12:07:55 +0530402
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400403 ath9k_ps_wakeup(sc);
404
Sujithff37e332008-11-24 12:07:55 +0530405 if (status & ATH9K_INT_FATAL) {
Sujithff37e332008-11-24 12:07:55 +0530406 ath_reset(sc, false);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400407 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530408 return;
Sujithff37e332008-11-24 12:07:55 +0530409 }
410
Sujith063d8be2009-03-30 15:28:49 +0530411 if (status & (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
412 spin_lock_bh(&sc->rx.rxflushlock);
413 ath_rx_tasklet(sc, 0);
414 spin_unlock_bh(&sc->rx.rxflushlock);
415 }
416
417 if (status & ATH9K_INT_TX)
418 ath_tx_tasklet(sc);
419
Gabor Juhos96148322009-07-24 17:27:21 +0200420 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
Jouni Malinen54ce8462009-05-19 17:01:40 +0300421 /*
422 * TSF sync does not look correct; remain awake to sync with
423 * the next Beacon.
424 */
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700425 ath_print(common, ATH_DBG_PS,
426 "TSFOOR - Sync with next Beacon\n");
Sujith1b04b932010-01-08 10:36:05 +0530427 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
Jouni Malinen54ce8462009-05-19 17:01:40 +0300428 }
429
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -0700430 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530431 if (status & ATH9K_INT_GENTIMER)
432 ath_gen_timer_isr(sc->sc_ah);
433
Sujithff37e332008-11-24 12:07:55 +0530434 /* re-enable hardware interrupt */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -0700435 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400436 ath9k_ps_restore(sc);
Sujithff37e332008-11-24 12:07:55 +0530437}
438
Gabor Juhos6baff7f2009-01-14 20:17:06 +0100439irqreturn_t ath_isr(int irq, void *dev)
Sujithff37e332008-11-24 12:07:55 +0530440{
Sujith063d8be2009-03-30 15:28:49 +0530441#define SCHED_INTR ( \
442 ATH9K_INT_FATAL | \
443 ATH9K_INT_RXORN | \
444 ATH9K_INT_RXEOL | \
445 ATH9K_INT_RX | \
446 ATH9K_INT_TX | \
447 ATH9K_INT_BMISS | \
448 ATH9K_INT_CST | \
Vasanthakumar Thiagarajanebb8e1d2009-09-01 17:46:32 +0530449 ATH9K_INT_TSFOOR | \
450 ATH9K_INT_GENTIMER)
Sujith063d8be2009-03-30 15:28:49 +0530451
Sujithff37e332008-11-24 12:07:55 +0530452 struct ath_softc *sc = dev;
Sujithcbe61d82009-02-09 13:27:12 +0530453 struct ath_hw *ah = sc->sc_ah;
Sujithff37e332008-11-24 12:07:55 +0530454 enum ath9k_int status;
455 bool sched = false;
456
Sujith063d8be2009-03-30 15:28:49 +0530457 /*
458 * The hardware is not ready/present, don't
459 * touch anything. Note this can happen early
460 * on if the IRQ is shared.
461 */
462 if (sc->sc_flags & SC_OP_INVALID)
463 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530464
Sujithff37e332008-11-24 12:07:55 +0530465
Sujith063d8be2009-03-30 15:28:49 +0530466 /* shared irq, not for us */
Sujithff37e332008-11-24 12:07:55 +0530467
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400468 if (!ath9k_hw_intrpend(ah))
Sujith063d8be2009-03-30 15:28:49 +0530469 return IRQ_NONE;
Sujithff37e332008-11-24 12:07:55 +0530470
Sujith063d8be2009-03-30 15:28:49 +0530471 /*
472 * Figure out the reason(s) for the interrupt. Note
473 * that the hal returns a pseudo-ISR that may include
474 * bits we haven't explicitly enabled so we mask the
475 * value to insure we only process bits we requested.
476 */
477 ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
478 status &= sc->imask; /* discard unasked-for bits */
479
480 /*
481 * If there are no status bits set, then this interrupt was not
482 * for me (should have been caught above).
483 */
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400484 if (!status)
Sujith063d8be2009-03-30 15:28:49 +0530485 return IRQ_NONE;
Sujith063d8be2009-03-30 15:28:49 +0530486
487 /* Cache the status */
488 sc->intrstatus = status;
489
490 if (status & SCHED_INTR)
491 sched = true;
492
493 /*
494 * If a FATAL or RXORN interrupt is received, we have to reset the
495 * chip immediately.
496 */
497 if (status & (ATH9K_INT_FATAL | ATH9K_INT_RXORN))
498 goto chip_reset;
499
500 if (status & ATH9K_INT_SWBA)
501 tasklet_schedule(&sc->bcon_tasklet);
502
503 if (status & ATH9K_INT_TXURN)
504 ath9k_hw_updatetxtriglevel(ah, true);
505
506 if (status & ATH9K_INT_MIB) {
507 /*
508 * Disable interrupts until we service the MIB
509 * interrupt; otherwise it will continue to
510 * fire.
511 */
512 ath9k_hw_set_interrupts(ah, 0);
513 /*
514 * Let the hal handle the event. We assume
515 * it will clear whatever condition caused
516 * the interrupt.
517 */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530518 ath9k_hw_procmibevent(ah);
Sujith063d8be2009-03-30 15:28:49 +0530519 ath9k_hw_set_interrupts(ah, sc->imask);
520 }
521
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400522 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
523 if (status & ATH9K_INT_TIM_TIMER) {
Sujith063d8be2009-03-30 15:28:49 +0530524 /* Clear RxAbort bit so that we can
525 * receive frames */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700526 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vasanthakumar Thiagarajan153e0802009-05-15 02:47:16 -0400527 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +0530528 sc->ps_flags |= PS_WAIT_FOR_BEACON;
Sujith063d8be2009-03-30 15:28:49 +0530529 }
Sujith063d8be2009-03-30 15:28:49 +0530530
531chip_reset:
532
Sujith817e11d2008-12-07 21:42:44 +0530533 ath_debug_stat_interrupt(sc, status);
534
Sujithff37e332008-11-24 12:07:55 +0530535 if (sched) {
536 /* turn off every interrupt except SWBA */
Sujith17d79042009-02-09 13:27:03 +0530537 ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
Sujithff37e332008-11-24 12:07:55 +0530538 tasklet_schedule(&sc->intr_tq);
539 }
540
541 return IRQ_HANDLED;
Sujith063d8be2009-03-30 15:28:49 +0530542
543#undef SCHED_INTR
Sujithff37e332008-11-24 12:07:55 +0530544}
545
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700546static u32 ath_get_extchanmode(struct ath_softc *sc,
Sujith99405f92008-11-24 12:08:35 +0530547 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +0530548 enum nl80211_channel_type channel_type)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700549{
550 u32 chanmode = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700551
552 switch (chan->band) {
553 case IEEE80211_BAND_2GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530554 switch(channel_type) {
555 case NL80211_CHAN_NO_HT:
556 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700557 chanmode = CHANNEL_G_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530558 break;
559 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700560 chanmode = CHANNEL_G_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530561 break;
562 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700563 chanmode = CHANNEL_G_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530564 break;
565 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700566 break;
567 case IEEE80211_BAND_5GHZ:
Sujith094d05d2008-12-12 11:57:43 +0530568 switch(channel_type) {
569 case NL80211_CHAN_NO_HT:
570 case NL80211_CHAN_HT20:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700571 chanmode = CHANNEL_A_HT20;
Sujith094d05d2008-12-12 11:57:43 +0530572 break;
573 case NL80211_CHAN_HT40PLUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700574 chanmode = CHANNEL_A_HT40PLUS;
Sujith094d05d2008-12-12 11:57:43 +0530575 break;
576 case NL80211_CHAN_HT40MINUS:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700577 chanmode = CHANNEL_A_HT40MINUS;
Sujith094d05d2008-12-12 11:57:43 +0530578 break;
579 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700580 break;
581 default:
582 break;
583 }
584
585 return chanmode;
586}
587
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800588static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200589 struct ath9k_keyval *hk, const u8 *addr,
590 bool authenticator)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700591{
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800592 struct ath_hw *ah = common->ah;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200593 const u8 *key_rxmic;
594 const u8 *key_txmic;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700595
Jouni Malinen6ace2892008-12-17 13:32:17 +0200596 key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
597 key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700598
599 if (addr == NULL) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200600 /*
601 * Group key installation - only two key cache entries are used
602 * regardless of splitmic capability since group key is only
603 * used either for TX or RX.
604 */
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200605 if (authenticator) {
606 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
607 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
608 } else {
609 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
610 memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
611 }
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800612 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700613 }
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800614 if (!common->splitmic) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200615 /* TX and RX keys share the same key cache entry. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700616 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
617 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800618 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700619 }
Jouni Malinend216aaa2009-03-03 13:11:53 +0200620
621 /* Separate key cache entries for TX and RX */
622
623 /* TX key goes at first index, RX key at +32. */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700624 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800625 if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
Jouni Malinend216aaa2009-03-03 13:11:53 +0200626 /* TX MIC entry failed. No need to proceed further */
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800627 ath_print(common, ATH_DBG_FATAL,
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700628 "Setting TX MIC Key Failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700629 return 0;
630 }
631
632 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
633 /* XXX delete tx key on failure? */
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800634 return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200635}
636
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800637static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
Jouni Malinen6ace2892008-12-17 13:32:17 +0200638{
639 int i;
640
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800641 for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
642 if (test_bit(i, common->keymap) ||
643 test_bit(i + 64, common->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200644 continue; /* At least one part of TKIP key allocated */
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800645 if (common->splitmic &&
646 (test_bit(i + 32, common->keymap) ||
647 test_bit(i + 64 + 32, common->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200648 continue; /* At least one part of TKIP key allocated */
649
650 /* Found a free slot for a TKIP key */
651 return i;
652 }
653 return -1;
654}
655
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800656static int ath_reserve_key_cache_slot(struct ath_common *common)
Jouni Malinen6ace2892008-12-17 13:32:17 +0200657{
658 int i;
659
660 /* First, try to find slots that would not be available for TKIP. */
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800661 if (common->splitmic) {
662 for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
663 if (!test_bit(i, common->keymap) &&
664 (test_bit(i + 32, common->keymap) ||
665 test_bit(i + 64, common->keymap) ||
666 test_bit(i + 64 + 32, common->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200667 return i;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800668 if (!test_bit(i + 32, common->keymap) &&
669 (test_bit(i, common->keymap) ||
670 test_bit(i + 64, common->keymap) ||
671 test_bit(i + 64 + 32, common->keymap)))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200672 return i + 32;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800673 if (!test_bit(i + 64, common->keymap) &&
674 (test_bit(i , common->keymap) ||
675 test_bit(i + 32, common->keymap) ||
676 test_bit(i + 64 + 32, common->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200677 return i + 64;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800678 if (!test_bit(i + 64 + 32, common->keymap) &&
679 (test_bit(i, common->keymap) ||
680 test_bit(i + 32, common->keymap) ||
681 test_bit(i + 64, common->keymap)))
Jouni Malinenea612132008-12-18 14:31:10 +0200682 return i + 64 + 32;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200683 }
684 } else {
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800685 for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
686 if (!test_bit(i, common->keymap) &&
687 test_bit(i + 64, common->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200688 return i;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800689 if (test_bit(i, common->keymap) &&
690 !test_bit(i + 64, common->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200691 return i + 64;
692 }
693 }
694
695 /* No partially used TKIP slots, pick any available slot */
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800696 for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200697 /* Do not allow slots that could be needed for TKIP group keys
698 * to be used. This limitation could be removed if we know that
699 * TKIP will not be used. */
700 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
701 continue;
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800702 if (common->splitmic) {
Jouni Malinenbe2864c2008-12-18 14:33:00 +0200703 if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
704 continue;
705 if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
706 continue;
707 }
708
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800709 if (!test_bit(i, common->keymap))
Jouni Malinen6ace2892008-12-17 13:32:17 +0200710 return i; /* Found a free slot for a key */
711 }
712
713 /* No free slot found */
714 return -1;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700715}
716
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800717static int ath_key_config(struct ath_common *common,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200718 struct ieee80211_vif *vif,
Johannes Bergdc822b52008-12-29 12:55:09 +0100719 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700720 struct ieee80211_key_conf *key)
721{
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800722 struct ath_hw *ah = common->ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700723 struct ath9k_keyval hk;
724 const u8 *mac = NULL;
725 int ret = 0;
Jouni Malinen6ace2892008-12-17 13:32:17 +0200726 int idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700727
728 memset(&hk, 0, sizeof(hk));
729
730 switch (key->alg) {
731 case ALG_WEP:
732 hk.kv_type = ATH9K_CIPHER_WEP;
733 break;
734 case ALG_TKIP:
735 hk.kv_type = ATH9K_CIPHER_TKIP;
736 break;
737 case ALG_CCMP:
738 hk.kv_type = ATH9K_CIPHER_AES_CCM;
739 break;
740 default:
Jouni Malinenca470b22009-01-08 13:32:12 +0200741 return -EOPNOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700742 }
743
Jouni Malinen6ace2892008-12-17 13:32:17 +0200744 hk.kv_len = key->keylen;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700745 memcpy(hk.kv_val, key->key, key->keylen);
746
Jouni Malinen6ace2892008-12-17 13:32:17 +0200747 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
748 /* For now, use the default keys for broadcast keys. This may
749 * need to change with virtual interfaces. */
750 idx = key->keyidx;
751 } else if (key->keyidx) {
Johannes Bergdc822b52008-12-29 12:55:09 +0100752 if (WARN_ON(!sta))
753 return -EOPNOTSUPP;
754 mac = sta->addr;
755
Jouni Malinen6ace2892008-12-17 13:32:17 +0200756 if (vif->type != NL80211_IFTYPE_AP) {
757 /* Only keyidx 0 should be used with unicast key, but
758 * allow this for client mode for now. */
759 idx = key->keyidx;
760 } else
761 return -EIO;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700762 } else {
Johannes Bergdc822b52008-12-29 12:55:09 +0100763 if (WARN_ON(!sta))
764 return -EOPNOTSUPP;
765 mac = sta->addr;
766
Jouni Malinen6ace2892008-12-17 13:32:17 +0200767 if (key->alg == ALG_TKIP)
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800768 idx = ath_reserve_key_cache_slot_tkip(common);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200769 else
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800770 idx = ath_reserve_key_cache_slot(common);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200771 if (idx < 0)
Jouni Malinenca470b22009-01-08 13:32:12 +0200772 return -ENOSPC; /* no free key cache entries */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700773 }
774
775 if (key->alg == ALG_TKIP)
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800776 ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
Jouni Malinen3f53dd62009-02-26 11:18:46 +0200777 vif->type == NL80211_IFTYPE_AP);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700778 else
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800779 ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700780
781 if (!ret)
782 return -EIO;
783
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800784 set_bit(idx, common->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200785 if (key->alg == ALG_TKIP) {
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800786 set_bit(idx + 64, common->keymap);
787 if (common->splitmic) {
788 set_bit(idx + 32, common->keymap);
789 set_bit(idx + 64 + 32, common->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200790 }
791 }
792
793 return idx;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700794}
795
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800796static void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700797{
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800798 struct ath_hw *ah = common->ah;
799
800 ath9k_hw_keyreset(ah, key->hw_key_idx);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200801 if (key->hw_key_idx < IEEE80211_WEP_NKID)
802 return;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700803
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800804 clear_bit(key->hw_key_idx, common->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200805 if (key->alg != ALG_TKIP)
806 return;
807
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -0800808 clear_bit(key->hw_key_idx + 64, common->keymap);
809 if (common->splitmic) {
810 clear_bit(key->hw_key_idx + 32, common->keymap);
811 clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
Jouni Malinen6ace2892008-12-17 13:32:17 +0200812 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700813}
814
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530815static void ath9k_bss_assoc_info(struct ath_softc *sc,
Sujith5640b082008-10-29 10:16:06 +0530816 struct ieee80211_vif *vif,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530817 struct ieee80211_bss_conf *bss_conf)
818{
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700819 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700820 struct ath_common *common = ath9k_hw_common(ah);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530821
822 if (bss_conf->assoc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700823 ath_print(common, ATH_DBG_CONFIG,
824 "Bss Info ASSOC %d, bssid: %pM\n",
825 bss_conf->aid, common->curbssid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530826
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530827 /* New association, store aid */
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700828 common->curaid = bss_conf->aid;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -0700829 ath9k_hw_write_associd(ah);
Jouni Malinenccdfeab2009-05-20 21:59:08 +0300830
Senthil Balasubramanian2664f202009-06-24 18:56:39 +0530831 /*
832 * Request a re-configuration of Beacon related timers
833 * on the receipt of the first Beacon frame (i.e.,
834 * after time sync with the AP).
835 */
Sujith1b04b932010-01-08 10:36:05 +0530836 sc->ps_flags |= PS_BEACON_SYNC;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530837
838 /* Configure the beacon */
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200839 ath_beacon_config(sc, vif);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530840
841 /* Reset rssi stats */
Vasanthakumar Thiagarajan22e66a42009-08-19 16:23:40 +0530842 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530843
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800844 ath_start_ani(common);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530845 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700846 ath_print(common, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
Luis R. Rodriguez15107182009-09-10 09:22:37 -0700847 common->curaid = 0;
Senthil Balasubramanianf38faa32009-06-24 18:56:40 +0530848 /* Stop ANI */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -0800849 del_timer_sync(&common->ani.timer);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530850 }
851}
852
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800853void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530854{
Sujithcbe61d82009-02-09 13:27:12 +0530855 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700856 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800857 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800858 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530859
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530860 ath9k_ps_wakeup(sc);
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530861 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithd2f5b3a2009-04-13 21:56:25 +0530862
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530863 if (!ah->curchan)
864 ah->curchan = ath_get_curchannel(sc, sc->hw);
865
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530866 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +0530867 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800868 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700869 ath_print(common, ATH_DBG_FATAL,
870 "Unable to reset channel %u (%uMhz) ",
871 "reset status %d\n",
872 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530873 }
874 spin_unlock_bh(&sc->sc_resetlock);
875
876 ath_update_txpow(sc);
877 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700878 ath_print(common, ATH_DBG_FATAL,
879 "Unable to restart recv logic\n");
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530880 return;
881 }
882
883 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200884 ath_beacon_config(sc, NULL); /* restart beacons */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530885
886 /* Re-Enable interrupts */
Sujith17d79042009-02-09 13:27:03 +0530887 ath9k_hw_set_interrupts(ah, sc->imask);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530888
889 /* Enable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530890 ath9k_hw_cfg_output(ah, ah->led_pin,
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530891 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530892 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530893
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800894 ieee80211_wake_queues(hw);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530895 ath9k_ps_restore(sc);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530896}
897
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800898void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530899{
Sujithcbe61d82009-02-09 13:27:12 +0530900 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800901 struct ieee80211_channel *channel = hw->conf.channel;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800902 int r;
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530903
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530904 ath9k_ps_wakeup(sc);
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800905 ieee80211_stop_queues(hw);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530906
907 /* Disable LED */
Vivek Natarajan08fc5c12009-08-14 11:30:52 +0530908 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
909 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530910
911 /* Disable interrupts */
912 ath9k_hw_set_interrupts(ah, 0);
913
Sujith043a0402009-01-16 21:38:47 +0530914 ath_drain_all_txq(sc, false); /* clear pending tx frames */
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530915 ath_stoprecv(sc); /* turn off frame recv */
916 ath_flushrecv(sc); /* flush recv queue */
917
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530918 if (!ah->curchan)
Luis R. Rodriguez68a89112009-11-02 14:35:42 -0800919 ah->curchan = ath_get_curchannel(sc, hw);
Vasanthakumar Thiagarajan159cd462009-06-13 14:50:25 +0530920
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530921 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +0530922 r = ath9k_hw_reset(ah, ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800923 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700924 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
925 "Unable to reset channel %u (%uMhz) "
926 "reset status %d\n",
927 channel->center_freq, r);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530928 }
929 spin_unlock_bh(&sc->sc_resetlock);
930
931 ath9k_hw_phy_disable(ah);
Vivek Natarajan93b1b372009-09-17 09:24:58 +0530932 ath9k_hw_configpcipowersave(ah, 1, 1);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +0530933 ath9k_ps_restore(sc);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -0700934 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530935}
936
Sujithff37e332008-11-24 12:07:55 +0530937int ath_reset(struct ath_softc *sc, bool retry_tx)
938{
Sujithcbe61d82009-02-09 13:27:12 +0530939 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700940 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguez030bb492008-12-23 15:58:37 -0800941 struct ieee80211_hw *hw = sc->hw;
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800942 int r;
Sujithff37e332008-11-24 12:07:55 +0530943
Sujith2ab81d42009-12-14 16:34:56 +0530944 /* Stop ANI */
945 del_timer_sync(&common->ani.timer);
946
Sujithff37e332008-11-24 12:07:55 +0530947 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530948 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +0530949 ath_stoprecv(sc);
950 ath_flushrecv(sc);
951
952 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +0530953 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800954 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700955 ath_print(common, ATH_DBG_FATAL,
956 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +0530957 spin_unlock_bh(&sc->sc_resetlock);
958
959 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700960 ath_print(common, ATH_DBG_FATAL,
961 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +0530962
963 /*
964 * We may be doing a reset in response to a request
965 * that changes the channel so update any state that
966 * might change as a result.
967 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800968 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +0530969
970 ath_update_txpow(sc);
971
972 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200973 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +0530974
Sujith17d79042009-02-09 13:27:03 +0530975 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +0530976
977 if (retry_tx) {
978 int i;
979 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
980 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +0530981 spin_lock_bh(&sc->tx.txq[i].axq_lock);
982 ath_txq_schedule(sc, &sc->tx.txq[i]);
983 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +0530984 }
985 }
986 }
987
Sujith2ab81d42009-12-14 16:34:56 +0530988 /* Start ANI */
989 ath_start_ani(common);
990
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800991 return r;
Sujithff37e332008-11-24 12:07:55 +0530992}
993
Sujithff37e332008-11-24 12:07:55 +0530994int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
995{
996 int qnum;
997
998 switch (queue) {
999 case 0:
Sujithb77f4832008-12-07 21:44:03 +05301000 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301001 break;
1002 case 1:
Sujithb77f4832008-12-07 21:44:03 +05301003 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301004 break;
1005 case 2:
Sujithb77f4832008-12-07 21:44:03 +05301006 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301007 break;
1008 case 3:
Sujithb77f4832008-12-07 21:44:03 +05301009 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301010 break;
1011 default:
Sujithb77f4832008-12-07 21:44:03 +05301012 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301013 break;
1014 }
1015
1016 return qnum;
1017}
1018
1019int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1020{
1021 int qnum;
1022
1023 switch (queue) {
1024 case ATH9K_WME_AC_VO:
1025 qnum = 0;
1026 break;
1027 case ATH9K_WME_AC_VI:
1028 qnum = 1;
1029 break;
1030 case ATH9K_WME_AC_BE:
1031 qnum = 2;
1032 break;
1033 case ATH9K_WME_AC_BK:
1034 qnum = 3;
1035 break;
1036 default:
1037 qnum = -1;
1038 break;
1039 }
1040
1041 return qnum;
1042}
1043
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001044/* XXX: Remove me once we don't depend on ath9k_channel for all
1045 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001046void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1047 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001048{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001049 struct ieee80211_channel *chan = hw->conf.channel;
1050 struct ieee80211_conf *conf = &hw->conf;
1051
1052 ichan->channel = chan->center_freq;
1053 ichan->chan = chan;
1054
1055 if (chan->band == IEEE80211_BAND_2GHZ) {
1056 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05301057 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001058 } else {
1059 ichan->chanmode = CHANNEL_A;
1060 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1061 }
1062
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001063 if (conf_is_ht(conf))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001064 ichan->chanmode = ath_get_extchanmode(sc, chan,
1065 conf->channel_type);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001066}
1067
Sujithff37e332008-11-24 12:07:55 +05301068/**********************/
1069/* mac80211 callbacks */
1070/**********************/
1071
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001072static int ath9k_start(struct ieee80211_hw *hw)
1073{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001074 struct ath_wiphy *aphy = hw->priv;
1075 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001076 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001077 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001078 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301079 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301080 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001081
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001082 ath_print(common, ATH_DBG_CONFIG,
1083 "Starting driver with initial channel: %d MHz\n",
1084 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001085
Sujith141b38b2009-02-04 08:10:07 +05301086 mutex_lock(&sc->mutex);
1087
Jouni Malinen9580a222009-03-03 19:23:33 +02001088 if (ath9k_wiphy_started(sc)) {
1089 if (sc->chan_idx == curchan->hw_value) {
1090 /*
1091 * Already on the operational channel, the new wiphy
1092 * can be marked active.
1093 */
1094 aphy->state = ATH_WIPHY_ACTIVE;
1095 ieee80211_wake_queues(hw);
1096 } else {
1097 /*
1098 * Another wiphy is on another channel, start the new
1099 * wiphy in paused state.
1100 */
1101 aphy->state = ATH_WIPHY_PAUSED;
1102 ieee80211_stop_queues(hw);
1103 }
1104 mutex_unlock(&sc->mutex);
1105 return 0;
1106 }
1107 aphy->state = ATH_WIPHY_ACTIVE;
1108
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001109 /* setup initial channel */
1110
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301111 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001112
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301113 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001114
Sujithff37e332008-11-24 12:07:55 +05301115 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001116 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05301117
1118 /*
1119 * The basic interface to setting the hardware in a good
1120 * state is ``reset''. On return the hardware is known to
1121 * be powered up and with interrupts disabled. This must
1122 * be followed by initialization of the appropriate bits
1123 * and then setup of the interrupt mask.
1124 */
1125 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001126 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001127 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001128 ath_print(common, ATH_DBG_FATAL,
1129 "Unable to reset hardware; reset status %d "
1130 "(freq %u MHz)\n", r,
1131 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05301132 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05301133 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001134 }
Sujithff37e332008-11-24 12:07:55 +05301135 spin_unlock_bh(&sc->sc_resetlock);
1136
1137 /*
1138 * This is needed only to setup initial state
1139 * but it's best done after a reset.
1140 */
1141 ath_update_txpow(sc);
1142
1143 /*
1144 * Setup the hardware after reset:
1145 * The receive engine is set going.
1146 * Frame transmit is handled entirely
1147 * in the frame output path; there's nothing to do
1148 * here except setup the interrupt mask.
1149 */
1150 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001151 ath_print(common, ATH_DBG_FATAL,
1152 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05301153 r = -EIO;
1154 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05301155 }
1156
1157 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05301158 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05301159 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
1160 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
1161
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001162 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05301163 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05301164
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001165 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05301166 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05301167
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001168 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301169
1170 sc->sc_flags &= ~SC_OP_INVALID;
1171
1172 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05301173 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001174 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301175
Jouni Malinenbce048d2009-03-03 19:23:28 +02001176 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001177
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001178 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001179
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001180 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
1181 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07001182 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1183 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001184 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05301185
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001186 if (common->bus_ops->bt_coex_prep)
1187 common->bus_ops->bt_coex_prep(common);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001188 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001189 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301190 }
1191
Sujith141b38b2009-02-04 08:10:07 +05301192mutex_unlock:
1193 mutex_unlock(&sc->mutex);
1194
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001195 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001196}
1197
1198static int ath9k_tx(struct ieee80211_hw *hw,
1199 struct sk_buff *skb)
1200{
Jouni Malinen147583c2008-08-11 14:01:50 +03001201 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02001202 struct ath_wiphy *aphy = hw->priv;
1203 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001204 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05301205 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +01001206 int padpos, padsize;
1207 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Sujith528f0c62008-10-29 10:14:26 +05301208
Jouni Malinen8089cc42009-03-03 19:23:38 +02001209 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001210 ath_print(common, ATH_DBG_XMIT,
1211 "ath9k: %s: TX in unexpected wiphy state "
1212 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02001213 goto exit;
1214 }
1215
Gabor Juhos96148322009-07-24 17:27:21 +02001216 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03001217 /*
1218 * mac80211 does not set PM field for normal data frames, so we
1219 * need to update that based on the current PS mode.
1220 */
1221 if (ieee80211_is_data(hdr->frame_control) &&
1222 !ieee80211_is_nullfunc(hdr->frame_control) &&
1223 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001224 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
1225 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03001226 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1227 }
1228 }
1229
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001230 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
1231 /*
1232 * We are using PS-Poll and mac80211 can request TX while in
1233 * power save mode. Need to wake up hardware for the TX to be
1234 * completed and if needed, also for RX of buffered frames.
1235 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001236 ath9k_ps_wakeup(sc);
1237 ath9k_hw_setrxabort(sc->sc_ah, 0);
1238 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001239 ath_print(common, ATH_DBG_PS,
1240 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +05301241 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001242 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001243 ath_print(common, ATH_DBG_PS,
1244 "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +05301245 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001246 }
1247 /*
1248 * The actual restore operation will happen only after
1249 * the sc_flags bit is cleared. We are just dropping
1250 * the ps_usecount here.
1251 */
1252 ath9k_ps_restore(sc);
1253 }
1254
Sujith528f0c62008-10-29 10:14:26 +05301255 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03001256
1257 /*
1258 * As a temporary workaround, assign seq# here; this will likely need
1259 * to be cleaned up to work better with Beacon transmission and virtual
1260 * BSSes.
1261 */
1262 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Jouni Malinen147583c2008-08-11 14:01:50 +03001263 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05301264 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03001265 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05301266 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03001267 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001268
1269 /* Add the padding after the header if this is not already done */
Benoit Papillault1bc14882009-11-24 15:49:18 +01001270 padpos = ath9k_cmn_padpos(hdr->frame_control);
1271 padsize = padpos & 3;
1272 if (padsize && skb->len>padpos) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001273 if (skb_headroom(skb) < padsize)
1274 return -1;
1275 skb_push(skb, padsize);
Benoit Papillault1bc14882009-11-24 15:49:18 +01001276 memmove(skb->data, skb->data + padsize, padpos);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001277 }
1278
Sujith528f0c62008-10-29 10:14:26 +05301279 /* Check if a tx queue is available */
1280
1281 txctl.txq = ath_test_get_txq(sc, skb);
1282 if (!txctl.txq)
1283 goto exit;
1284
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001285 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001286
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001287 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001288 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05301289 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290 }
1291
1292 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301293exit:
1294 dev_kfree_skb_any(skb);
1295 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001296}
1297
1298static void ath9k_stop(struct ieee80211_hw *hw)
1299{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001300 struct ath_wiphy *aphy = hw->priv;
1301 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001302 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001303 struct ath_common *common = ath9k_hw_common(ah);
Sujith9c84b792008-10-29 10:17:13 +05301304
Sujith4c483812009-08-18 10:51:52 +05301305 mutex_lock(&sc->mutex);
1306
Jouni Malinen9580a222009-03-03 19:23:33 +02001307 aphy->state = ATH_WIPHY_INACTIVE;
1308
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001309 cancel_delayed_work_sync(&sc->ath_led_blink_work);
1310 cancel_delayed_work_sync(&sc->tx_complete_work);
1311
1312 if (!sc->num_sec_wiphy) {
1313 cancel_delayed_work_sync(&sc->wiphy_work);
1314 cancel_work_sync(&sc->chan_work);
1315 }
1316
Sujith9c84b792008-10-29 10:17:13 +05301317 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001318 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05301319 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05301320 return;
1321 }
1322
Jouni Malinen9580a222009-03-03 19:23:33 +02001323 if (ath9k_wiphy_started(sc)) {
1324 mutex_unlock(&sc->mutex);
1325 return; /* another wiphy still in use */
1326 }
1327
Sujith3867cf62009-12-23 20:03:27 -05001328 /* Ensure HW is awake when we try to shut it down. */
1329 ath9k_ps_wakeup(sc);
1330
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001331 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001332 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001333 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001334 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301335 }
1336
Sujithff37e332008-11-24 12:07:55 +05301337 /* make sure h/w will not generate any interrupt
1338 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001339 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05301340
1341 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05301342 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05301343 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001344 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05301345 } else
Sujithb77f4832008-12-07 21:44:03 +05301346 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05301347
Sujithff37e332008-11-24 12:07:55 +05301348 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001349 ath9k_hw_disable(ah);
1350 ath9k_hw_configpcipowersave(ah, 1, 1);
Sujith3867cf62009-12-23 20:03:27 -05001351 ath9k_ps_restore(sc);
1352
1353 /* Finally, put the chip in FULL SLEEP mode */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001354 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05301355
1356 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001357
Sujith141b38b2009-02-04 08:10:07 +05301358 mutex_unlock(&sc->mutex);
1359
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001360 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361}
1362
1363static int ath9k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001364 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001365{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001366 struct ath_wiphy *aphy = hw->priv;
1367 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001368 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001369 struct ath_vif *avp = (void *)vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08001370 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001371 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001372
Sujith141b38b2009-02-04 08:10:07 +05301373 mutex_lock(&sc->mutex);
1374
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001375 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
1376 sc->nvifs > 0) {
1377 ret = -ENOBUFS;
1378 goto out;
1379 }
1380
Johannes Berg1ed32e42009-12-23 13:15:45 +01001381 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001382 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08001383 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001384 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001385 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02001386 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04001387 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001388 if (sc->nbcnvifs >= ATH_BCBUF) {
1389 ret = -ENOBUFS;
1390 goto out;
1391 }
Johannes Berg1ed32e42009-12-23 13:15:45 +01001392 ic_opmode = vif->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001393 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001394 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001395 ath_print(common, ATH_DBG_FATAL,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001396 "Interface type %d not yet supported\n", vif->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001397 ret = -EOPNOTSUPP;
1398 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001399 }
1400
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001401 ath_print(common, ATH_DBG_CONFIG,
1402 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001403
Sujith17d79042009-02-09 13:27:03 +05301404 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05301405 avp->av_opmode = ic_opmode;
1406 avp->av_bslot = -1;
1407
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001408 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001409
1410 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
1411 ath9k_set_bssid_mask(hw);
1412
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001413 if (sc->nvifs > 1)
1414 goto out; /* skip global settings for secondary vif */
1415
Sujithb238e902009-03-03 10:16:56 +05301416 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05301417 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05301418 sc->sc_flags |= SC_OP_TSF_RESET;
1419 }
Sujith5640b082008-10-29 10:16:06 +05301420
Sujith5640b082008-10-29 10:16:06 +05301421 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05301422 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05301423
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301424 /*
1425 * Enable MIB interrupts when there are hardware phy counters.
1426 * Note we only do this (at the moment) for station mode.
1427 */
Johannes Berg1ed32e42009-12-23 13:15:45 +01001428 if ((vif->type == NL80211_IFTYPE_STATION) ||
1429 (vif->type == NL80211_IFTYPE_ADHOC) ||
1430 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05301431 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05301432 sc->imask |= ATH9K_INT_TSFOOR;
1433 }
1434
Sujith17d79042009-02-09 13:27:03 +05301435 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301436
Johannes Berg1ed32e42009-12-23 13:15:45 +01001437 if (vif->type == NL80211_IFTYPE_AP ||
1438 vif->type == NL80211_IFTYPE_ADHOC ||
1439 vif->type == NL80211_IFTYPE_MONITOR)
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001440 ath_start_ani(common);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001441
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001442out:
Sujith141b38b2009-02-04 08:10:07 +05301443 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001444 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001445}
1446
1447static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001448 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001449{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001450 struct ath_wiphy *aphy = hw->priv;
1451 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001452 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001453 struct ath_vif *avp = (void *)vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001454 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001455
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001456 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001457
Sujith141b38b2009-02-04 08:10:07 +05301458 mutex_lock(&sc->mutex);
1459
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001460 /* Stop ANI */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001461 del_timer_sync(&common->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001463 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04001464 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
1465 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
1466 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001467 ath9k_ps_wakeup(sc);
Sujithb77f4832008-12-07 21:44:03 +05301468 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001469 ath_beacon_return(sc, avp);
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001470 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001471 }
1472
Sujith672840a2008-08-11 14:05:08 +05301473 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001474
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001475 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Johannes Berg1ed32e42009-12-23 13:15:45 +01001476 if (sc->beacon.bslot[i] == vif) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001477 printk(KERN_DEBUG "%s: vif had allocated beacon "
1478 "slot\n", __func__);
1479 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001480 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001481 }
1482 }
1483
Sujith17d79042009-02-09 13:27:03 +05301484 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05301485
1486 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001487}
1488
Johannes Berge8975582008-10-09 12:18:51 +02001489static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001490{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001491 struct ath_wiphy *aphy = hw->priv;
1492 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001493 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berge8975582008-10-09 12:18:51 +02001494 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05301495 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001496 bool disable_radio;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001497
Sujithaa33de02008-12-18 11:40:16 +05301498 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301499
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001500 /*
1501 * Leave this as the first check because we need to turn on the
1502 * radio if it was disabled before prior to processing the rest
1503 * of the changes. Likewise we must only disable the radio towards
1504 * the end.
1505 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001506 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001507 bool enable_radio;
1508 bool all_wiphys_idle;
1509 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001510
1511 spin_lock_bh(&sc->wiphy_lock);
1512 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001513 ath9k_set_wiphy_idle(aphy, idle);
1514
1515 if (!idle && all_wiphys_idle)
1516 enable_radio = true;
1517
1518 /*
1519 * After we unlock here its possible another wiphy
1520 * can be re-renabled so to account for that we will
1521 * only disable the radio toward the end of this routine
1522 * if by then all wiphys are still idle.
1523 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001524 spin_unlock_bh(&sc->wiphy_lock);
1525
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001526 if (enable_radio) {
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001527 ath_radio_enable(sc, hw);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001528 ath_print(common, ATH_DBG_CONFIG,
1529 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001530 }
1531 }
1532
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001533 /*
1534 * We just prepare to enable PS. We have to wait until our AP has
1535 * ACK'd our null data frame to disable RX otherwise we'll ignore
1536 * those ACKs and end up retransmitting the same null data frames.
1537 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1538 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301539 if (changed & IEEE80211_CONF_CHANGE_PS) {
1540 if (conf->flags & IEEE80211_CONF_PS) {
Sujith1b04b932010-01-08 10:36:05 +05301541 sc->ps_flags |= PS_ENABLED;
Vivek Natarajan8782b412009-03-30 14:17:00 +05301542 if (!(ah->caps.hw_caps &
1543 ATH9K_HW_CAP_AUTOSLEEP)) {
1544 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
1545 sc->imask |= ATH9K_INT_TIM_TIMER;
1546 ath9k_hw_set_interrupts(sc->sc_ah,
1547 sc->imask);
1548 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301549 }
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001550 /*
1551 * At this point we know hardware has received an ACK
1552 * of a previously sent null data frame.
1553 */
Sujith1b04b932010-01-08 10:36:05 +05301554 if ((sc->ps_flags & PS_NULLFUNC_COMPLETED)) {
1555 sc->ps_flags &= ~PS_NULLFUNC_COMPLETED;
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001556 sc->ps_enabled = true;
1557 ath9k_hw_setrxabort(sc->sc_ah, 1);
1558 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301559 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02001560 sc->ps_enabled = false;
Sujith1b04b932010-01-08 10:36:05 +05301561 sc->ps_flags &= ~(PS_ENABLED |
1562 PS_NULLFUNC_COMPLETED);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001563 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05301564 if (!(ah->caps.hw_caps &
1565 ATH9K_HW_CAP_AUTOSLEEP)) {
1566 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +05301567 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1568 PS_WAIT_FOR_CAB |
1569 PS_WAIT_FOR_PSPOLL_DATA |
1570 PS_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05301571 if (sc->imask & ATH9K_INT_TIM_TIMER) {
1572 sc->imask &= ~ATH9K_INT_TIM_TIMER;
1573 ath9k_hw_set_interrupts(sc->sc_ah,
1574 sc->imask);
1575 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301576 }
1577 }
1578 }
1579
Johannes Berg47979382009-01-07 10:13:27 +01001580 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05301581 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001582 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001583
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001584 aphy->chan_idx = pos;
1585 aphy->chan_is_ht = conf_is_ht(conf);
1586
Jouni Malinen8089cc42009-03-03 19:23:38 +02001587 if (aphy->state == ATH_WIPHY_SCAN ||
1588 aphy->state == ATH_WIPHY_ACTIVE)
1589 ath9k_wiphy_pause_all_forced(sc, aphy);
1590 else {
1591 /*
1592 * Do not change operational channel based on a paused
1593 * wiphy changes.
1594 */
1595 goto skip_chan_change;
1596 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001597
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001598 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1599 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02001600
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001601 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001602 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05301603
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08001604 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05301605
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001606 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001607 ath_print(common, ATH_DBG_FATAL,
1608 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301609 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05301610 return -EINVAL;
1611 }
Sujith094d05d2008-12-12 11:57:43 +05301612 }
Sujith86b89ee2008-08-07 10:54:57 +05301613
Jouni Malinen8089cc42009-03-03 19:23:38 +02001614skip_chan_change:
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07001615 if (changed & IEEE80211_CONF_CHANGE_POWER)
Sujith17d79042009-02-09 13:27:03 +05301616 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001617
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001618 spin_lock_bh(&sc->wiphy_lock);
1619 disable_radio = ath9k_all_wiphys_idle(sc);
1620 spin_unlock_bh(&sc->wiphy_lock);
1621
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001622 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001623 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001624 ath_radio_disable(sc, hw);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001625 }
1626
Sujithaa33de02008-12-18 11:40:16 +05301627 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301628
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001629 return 0;
1630}
1631
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001632#define SUPPORTED_FILTERS \
1633 (FIF_PROMISC_IN_BSS | \
1634 FIF_ALLMULTI | \
1635 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001636 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001637 FIF_OTHER_BSS | \
1638 FIF_BCN_PRBRESP_PROMISC | \
1639 FIF_FCSFAIL)
1640
Sujith7dcfdcd2008-08-11 14:03:13 +05301641/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001642static void ath9k_configure_filter(struct ieee80211_hw *hw,
1643 unsigned int changed_flags,
1644 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001645 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001646{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001647 struct ath_wiphy *aphy = hw->priv;
1648 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05301649 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001650
1651 changed_flags &= SUPPORTED_FILTERS;
1652 *total_flags &= SUPPORTED_FILTERS;
1653
Sujithb77f4832008-12-07 21:44:03 +05301654 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001655 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301656 rfilt = ath_calcrxfilter(sc);
1657 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001658 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301659
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001660 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
1661 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001662}
1663
1664static void ath9k_sta_notify(struct ieee80211_hw *hw,
1665 struct ieee80211_vif *vif,
1666 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02001667 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001668{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001669 struct ath_wiphy *aphy = hw->priv;
1670 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001671
1672 switch (cmd) {
1673 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05301674 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001675 break;
1676 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05301677 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001678 break;
1679 default:
1680 break;
1681 }
1682}
1683
Sujith141b38b2009-02-04 08:10:07 +05301684static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001685 const struct ieee80211_tx_queue_params *params)
1686{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001687 struct ath_wiphy *aphy = hw->priv;
1688 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001689 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05301690 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001691 int ret = 0, qnum;
1692
1693 if (queue >= WME_NUM_AC)
1694 return 0;
1695
Sujith141b38b2009-02-04 08:10:07 +05301696 mutex_lock(&sc->mutex);
1697
Sujith1ffb0612009-03-30 15:28:46 +05301698 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1699
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001700 qi.tqi_aifs = params->aifs;
1701 qi.tqi_cwmin = params->cw_min;
1702 qi.tqi_cwmax = params->cw_max;
1703 qi.tqi_burstTime = params->txop;
1704 qnum = ath_get_hal_qnum(queue, sc);
1705
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001706 ath_print(common, ATH_DBG_CONFIG,
1707 "Configure tx [queue/halq] [%d/%d], "
1708 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1709 queue, qnum, params->aifs, params->cw_min,
1710 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001711
1712 ret = ath_txq_update(sc, qnum, &qi);
1713 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001714 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001715
Vivek Natarajan94db2932009-11-25 12:01:54 +05301716 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
1717 if ((qnum == sc->tx.hwq_map[ATH9K_WME_AC_BE]) && !ret)
1718 ath_beaconq_config(sc);
1719
Sujith141b38b2009-02-04 08:10:07 +05301720 mutex_unlock(&sc->mutex);
1721
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001722 return ret;
1723}
1724
1725static int ath9k_set_key(struct ieee80211_hw *hw,
1726 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001727 struct ieee80211_vif *vif,
1728 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729 struct ieee80211_key_conf *key)
1730{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001731 struct ath_wiphy *aphy = hw->priv;
1732 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001733 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734 int ret = 0;
1735
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001736 if (modparam_nohwcrypt)
1737 return -ENOSPC;
1738
Sujith141b38b2009-02-04 08:10:07 +05301739 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301740 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001741 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001742
1743 switch (cmd) {
1744 case SET_KEY:
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -08001745 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001746 if (ret >= 0) {
1747 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001748 /* push IV and Michael MIC generation to stack */
1749 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301750 if (key->alg == ALG_TKIP)
1751 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001752 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1753 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001754 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001755 }
1756 break;
1757 case DISABLE_KEY:
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -08001758 ath_key_delete(common, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001759 break;
1760 default:
1761 ret = -EINVAL;
1762 }
1763
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301764 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301765 mutex_unlock(&sc->mutex);
1766
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001767 return ret;
1768}
1769
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001770static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1771 struct ieee80211_vif *vif,
1772 struct ieee80211_bss_conf *bss_conf,
1773 u32 changed)
1774{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001775 struct ath_wiphy *aphy = hw->priv;
1776 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001777 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001778 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001779 struct ath_vif *avp = (void *)vif->drv_priv;
Sujithc6089cc2009-11-16 11:40:48 +05301780 int error;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001781
Sujith141b38b2009-02-04 08:10:07 +05301782 mutex_lock(&sc->mutex);
1783
Sujithc6089cc2009-11-16 11:40:48 +05301784 if (changed & BSS_CHANGED_BSSID) {
1785 /* Set BSSID */
1786 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1787 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001788 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001789 ath9k_hw_write_associd(ah);
Sujithc6089cc2009-11-16 11:40:48 +05301790
1791 /* Set aggregation protection mode parameters */
1792 sc->config.ath_aggr_prot = 0;
1793
1794 /* Only legacy IBSS for now */
1795 if (vif->type == NL80211_IFTYPE_ADHOC)
1796 ath_update_chainmask(sc, 0);
1797
1798 ath_print(common, ATH_DBG_CONFIG,
1799 "BSSID: %pM aid: 0x%x\n",
1800 common->curbssid, common->curaid);
1801
1802 /* need to reconfigure the beacon */
1803 sc->sc_flags &= ~SC_OP_BEACONS ;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001804 }
1805
Sujithc6089cc2009-11-16 11:40:48 +05301806 /* Enable transmission of beacons (AP, IBSS, MESH) */
1807 if ((changed & BSS_CHANGED_BEACON) ||
1808 ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
1809 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1810 error = ath_beacon_alloc(aphy, vif);
1811 if (!error)
1812 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001813 }
1814
Sujithc6089cc2009-11-16 11:40:48 +05301815 /* Disable transmission of beacons */
1816 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
1817 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1818
1819 if (changed & BSS_CHANGED_BEACON_INT) {
1820 sc->beacon_interval = bss_conf->beacon_int;
1821 /*
1822 * In case of AP mode, the HW TSF has to be reset
1823 * when the beacon interval changes.
1824 */
1825 if (vif->type == NL80211_IFTYPE_AP) {
1826 sc->sc_flags |= SC_OP_TSF_RESET;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001827 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001828 error = ath_beacon_alloc(aphy, vif);
1829 if (!error)
1830 ath_beacon_config(sc, vif);
Sujithc6089cc2009-11-16 11:40:48 +05301831 } else {
1832 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001833 }
1834 }
1835
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001836 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001837 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1838 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001839 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05301840 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001841 else
Sujith672840a2008-08-11 14:05:08 +05301842 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001843 }
1844
1845 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001846 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1847 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001848 if (bss_conf->use_cts_prot &&
1849 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05301850 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001851 else
Sujith672840a2008-08-11 14:05:08 +05301852 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001853 }
1854
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001855 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001856 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001857 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05301858 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001859 }
Sujith141b38b2009-02-04 08:10:07 +05301860
1861 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001862}
1863
1864static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
1865{
1866 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02001867 struct ath_wiphy *aphy = hw->priv;
1868 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001869
Sujith141b38b2009-02-04 08:10:07 +05301870 mutex_lock(&sc->mutex);
1871 tsf = ath9k_hw_gettsf64(sc->sc_ah);
1872 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873
1874 return tsf;
1875}
1876
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001877static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1878{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001879 struct ath_wiphy *aphy = hw->priv;
1880 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001881
Sujith141b38b2009-02-04 08:10:07 +05301882 mutex_lock(&sc->mutex);
1883 ath9k_hw_settsf64(sc->sc_ah, tsf);
1884 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001885}
1886
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001887static void ath9k_reset_tsf(struct ieee80211_hw *hw)
1888{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001889 struct ath_wiphy *aphy = hw->priv;
1890 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891
Sujith141b38b2009-02-04 08:10:07 +05301892 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001893
1894 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301895 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001896 ath9k_ps_restore(sc);
1897
Sujith141b38b2009-02-04 08:10:07 +05301898 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001899}
1900
1901static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01001902 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05301903 enum ieee80211_ampdu_mlme_action action,
1904 struct ieee80211_sta *sta,
1905 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001906{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001907 struct ath_wiphy *aphy = hw->priv;
1908 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001909 int ret = 0;
1910
1911 switch (action) {
1912 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05301913 if (!(sc->sc_flags & SC_OP_RXAGGR))
1914 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001915 break;
1916 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001917 break;
1918 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001919 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301920 ath_tx_aggr_start(sc, sta, tid, ssn);
Johannes Bergc951ad32009-11-16 12:00:38 +01001921 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001922 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001923 break;
1924 case IEEE80211_AMPDU_TX_STOP:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001925 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301926 ath_tx_aggr_stop(sc, sta, tid);
Johannes Bergc951ad32009-11-16 12:00:38 +01001927 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001928 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001929 break;
Johannes Bergb1720232009-03-23 17:28:39 +01001930 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001931 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05301932 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001933 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05301934 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001935 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001936 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1937 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001938 }
1939
1940 return ret;
1941}
1942
Sujith0c98de62009-03-03 10:16:45 +05301943static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
1944{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001945 struct ath_wiphy *aphy = hw->priv;
1946 struct ath_softc *sc = aphy->sc;
Sujith05c78d62009-12-14 14:57:04 +05301947 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith0c98de62009-03-03 10:16:45 +05301948
Sujith3d832612009-08-21 12:00:28 +05301949 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02001950 if (ath9k_wiphy_scanning(sc)) {
1951 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
1952 "same time\n");
1953 /*
1954 * Do not allow the concurrent scanning state for now. This
1955 * could be improved with scanning control moved into ath9k.
1956 */
Sujith3d832612009-08-21 12:00:28 +05301957 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02001958 return;
1959 }
1960
1961 aphy->state = ATH_WIPHY_SCAN;
1962 ath9k_wiphy_pause_all_forced(sc, aphy);
Sujith0c98de62009-03-03 10:16:45 +05301963 sc->sc_flags |= SC_OP_SCANNING;
Sujith05c78d62009-12-14 14:57:04 +05301964 del_timer_sync(&common->ani.timer);
Sujithb6ce5c32009-12-14 14:57:06 +05301965 cancel_delayed_work_sync(&sc->tx_complete_work);
Sujith3d832612009-08-21 12:00:28 +05301966 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05301967}
1968
1969static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
1970{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001971 struct ath_wiphy *aphy = hw->priv;
1972 struct ath_softc *sc = aphy->sc;
Sujith05c78d62009-12-14 14:57:04 +05301973 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith0c98de62009-03-03 10:16:45 +05301974
Sujith3d832612009-08-21 12:00:28 +05301975 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02001976 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05301977 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05301978 sc->sc_flags |= SC_OP_FULL_RESET;
Sujith05c78d62009-12-14 14:57:04 +05301979 ath_start_ani(common);
Sujithb6ce5c32009-12-14 14:57:06 +05301980 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Vivek Natarajand0bec342009-09-02 15:50:55 +05301981 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05301982 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05301983}
1984
Gabor Juhos6baff7f2009-01-14 20:17:06 +01001985struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001986 .tx = ath9k_tx,
1987 .start = ath9k_start,
1988 .stop = ath9k_stop,
1989 .add_interface = ath9k_add_interface,
1990 .remove_interface = ath9k_remove_interface,
1991 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001992 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001993 .sta_notify = ath9k_sta_notify,
1994 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001995 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001996 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001997 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001998 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001999 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002000 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05302001 .sw_scan_start = ath9k_sw_scan_start,
2002 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302003 .rfkill_poll = ath9k_rfkill_poll_state,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002004};