blob: 6f3e71c5071e865cdef63e08705be6e896e3a933 [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
Sujithcc9c3782010-01-08 10:36:09 +0530947 ieee80211_stop_queues(hw);
948
Sujithff37e332008-11-24 12:07:55 +0530949 ath9k_hw_set_interrupts(ah, 0);
Sujith043a0402009-01-16 21:38:47 +0530950 ath_drain_all_txq(sc, retry_tx);
Sujithff37e332008-11-24 12:07:55 +0530951 ath_stoprecv(sc);
952 ath_flushrecv(sc);
953
954 spin_lock_bh(&sc->sc_resetlock);
Sujith2660b812009-02-09 13:27:26 +0530955 r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800956 if (r)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700957 ath_print(common, ATH_DBG_FATAL,
958 "Unable to reset hardware; reset status %d\n", r);
Sujithff37e332008-11-24 12:07:55 +0530959 spin_unlock_bh(&sc->sc_resetlock);
960
961 if (ath_startrecv(sc) != 0)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700962 ath_print(common, ATH_DBG_FATAL,
963 "Unable to start recv logic\n");
Sujithff37e332008-11-24 12:07:55 +0530964
965 /*
966 * We may be doing a reset in response to a request
967 * that changes the channel so update any state that
968 * might change as a result.
969 */
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -0800970 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +0530971
972 ath_update_txpow(sc);
973
974 if (sc->sc_flags & SC_OP_BEACONS)
Jouni Malinen2c3db3d2009-03-03 19:23:26 +0200975 ath_beacon_config(sc, NULL); /* restart beacons */
Sujithff37e332008-11-24 12:07:55 +0530976
Sujith17d79042009-02-09 13:27:03 +0530977 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +0530978
979 if (retry_tx) {
980 int i;
981 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
982 if (ATH_TXQ_SETUP(sc, i)) {
Sujithb77f4832008-12-07 21:44:03 +0530983 spin_lock_bh(&sc->tx.txq[i].axq_lock);
984 ath_txq_schedule(sc, &sc->tx.txq[i]);
985 spin_unlock_bh(&sc->tx.txq[i].axq_lock);
Sujithff37e332008-11-24 12:07:55 +0530986 }
987 }
988 }
989
Sujithcc9c3782010-01-08 10:36:09 +0530990 ieee80211_wake_queues(hw);
991
Sujith2ab81d42009-12-14 16:34:56 +0530992 /* Start ANI */
993 ath_start_ani(common);
994
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -0800995 return r;
Sujithff37e332008-11-24 12:07:55 +0530996}
997
Sujithff37e332008-11-24 12:07:55 +0530998int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
999{
1000 int qnum;
1001
1002 switch (queue) {
1003 case 0:
Sujithb77f4832008-12-07 21:44:03 +05301004 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
Sujithff37e332008-11-24 12:07:55 +05301005 break;
1006 case 1:
Sujithb77f4832008-12-07 21:44:03 +05301007 qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
Sujithff37e332008-11-24 12:07:55 +05301008 break;
1009 case 2:
Sujithb77f4832008-12-07 21:44:03 +05301010 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301011 break;
1012 case 3:
Sujithb77f4832008-12-07 21:44:03 +05301013 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
Sujithff37e332008-11-24 12:07:55 +05301014 break;
1015 default:
Sujithb77f4832008-12-07 21:44:03 +05301016 qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
Sujithff37e332008-11-24 12:07:55 +05301017 break;
1018 }
1019
1020 return qnum;
1021}
1022
1023int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
1024{
1025 int qnum;
1026
1027 switch (queue) {
1028 case ATH9K_WME_AC_VO:
1029 qnum = 0;
1030 break;
1031 case ATH9K_WME_AC_VI:
1032 qnum = 1;
1033 break;
1034 case ATH9K_WME_AC_BE:
1035 qnum = 2;
1036 break;
1037 case ATH9K_WME_AC_BK:
1038 qnum = 3;
1039 break;
1040 default:
1041 qnum = -1;
1042 break;
1043 }
1044
1045 return qnum;
1046}
1047
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001048/* XXX: Remove me once we don't depend on ath9k_channel for all
1049 * this redundant data */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001050void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
1051 struct ath9k_channel *ichan)
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001052{
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001053 struct ieee80211_channel *chan = hw->conf.channel;
1054 struct ieee80211_conf *conf = &hw->conf;
1055
1056 ichan->channel = chan->center_freq;
1057 ichan->chan = chan;
1058
1059 if (chan->band == IEEE80211_BAND_2GHZ) {
1060 ichan->chanmode = CHANNEL_G;
Sujith88132622009-09-03 12:08:53 +05301061 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001062 } else {
1063 ichan->chanmode = CHANNEL_A;
1064 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
1065 }
1066
Luis R. Rodriguez25c56ee2009-09-13 23:04:44 -07001067 if (conf_is_ht(conf))
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001068 ichan->chanmode = ath_get_extchanmode(sc, chan,
1069 conf->channel_type);
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001070}
1071
Sujithff37e332008-11-24 12:07:55 +05301072/**********************/
1073/* mac80211 callbacks */
1074/**********************/
1075
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001076static int ath9k_start(struct ieee80211_hw *hw)
1077{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001078 struct ath_wiphy *aphy = hw->priv;
1079 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001080 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001081 struct ath_common *common = ath9k_hw_common(ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001082 struct ieee80211_channel *curchan = hw->conf.channel;
Sujithff37e332008-11-24 12:07:55 +05301083 struct ath9k_channel *init_channel;
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301084 int r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001085
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001086 ath_print(common, ATH_DBG_CONFIG,
1087 "Starting driver with initial channel: %d MHz\n",
1088 curchan->center_freq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001089
Sujith141b38b2009-02-04 08:10:07 +05301090 mutex_lock(&sc->mutex);
1091
Jouni Malinen9580a222009-03-03 19:23:33 +02001092 if (ath9k_wiphy_started(sc)) {
1093 if (sc->chan_idx == curchan->hw_value) {
1094 /*
1095 * Already on the operational channel, the new wiphy
1096 * can be marked active.
1097 */
1098 aphy->state = ATH_WIPHY_ACTIVE;
1099 ieee80211_wake_queues(hw);
1100 } else {
1101 /*
1102 * Another wiphy is on another channel, start the new
1103 * wiphy in paused state.
1104 */
1105 aphy->state = ATH_WIPHY_PAUSED;
1106 ieee80211_stop_queues(hw);
1107 }
1108 mutex_unlock(&sc->mutex);
1109 return 0;
1110 }
1111 aphy->state = ATH_WIPHY_ACTIVE;
1112
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001113 /* setup initial channel */
1114
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301115 sc->chan_idx = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001116
Vasanthakumar Thiagarajan82880a72009-06-13 14:50:24 +05301117 init_channel = ath_get_curchannel(sc, hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001118
Sujithff37e332008-11-24 12:07:55 +05301119 /* Reset SERDES registers */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001120 ath9k_hw_configpcipowersave(ah, 0, 0);
Sujithff37e332008-11-24 12:07:55 +05301121
1122 /*
1123 * The basic interface to setting the hardware in a good
1124 * state is ``reset''. On return the hardware is known to
1125 * be powered up and with interrupts disabled. This must
1126 * be followed by initialization of the appropriate bits
1127 * and then setup of the interrupt mask.
1128 */
1129 spin_lock_bh(&sc->sc_resetlock);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001130 r = ath9k_hw_reset(ah, init_channel, false);
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001131 if (r) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001132 ath_print(common, ATH_DBG_FATAL,
1133 "Unable to reset hardware; reset status %d "
1134 "(freq %u MHz)\n", r,
1135 curchan->center_freq);
Sujithff37e332008-11-24 12:07:55 +05301136 spin_unlock_bh(&sc->sc_resetlock);
Sujith141b38b2009-02-04 08:10:07 +05301137 goto mutex_unlock;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001138 }
Sujithff37e332008-11-24 12:07:55 +05301139 spin_unlock_bh(&sc->sc_resetlock);
1140
1141 /*
1142 * This is needed only to setup initial state
1143 * but it's best done after a reset.
1144 */
1145 ath_update_txpow(sc);
1146
1147 /*
1148 * Setup the hardware after reset:
1149 * The receive engine is set going.
1150 * Frame transmit is handled entirely
1151 * in the frame output path; there's nothing to do
1152 * here except setup the interrupt mask.
1153 */
1154 if (ath_startrecv(sc) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001155 ath_print(common, ATH_DBG_FATAL,
1156 "Unable to start recv logic\n");
Sujith141b38b2009-02-04 08:10:07 +05301157 r = -EIO;
1158 goto mutex_unlock;
Sujithff37e332008-11-24 12:07:55 +05301159 }
1160
1161 /* Setup our intr mask. */
Sujith17d79042009-02-09 13:27:03 +05301162 sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
Sujithff37e332008-11-24 12:07:55 +05301163 | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
1164 | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
1165
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001166 if (ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
Sujith17d79042009-02-09 13:27:03 +05301167 sc->imask |= ATH9K_INT_GTT;
Sujithff37e332008-11-24 12:07:55 +05301168
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001169 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
Sujith17d79042009-02-09 13:27:03 +05301170 sc->imask |= ATH9K_INT_CST;
Sujithff37e332008-11-24 12:07:55 +05301171
Luis R. Rodriguezce111ba2008-12-23 15:58:39 -08001172 ath_cache_conf_rate(sc, &hw->conf);
Sujithff37e332008-11-24 12:07:55 +05301173
1174 sc->sc_flags &= ~SC_OP_INVALID;
1175
1176 /* Disable BMISS interrupt when we're not associated */
Sujith17d79042009-02-09 13:27:03 +05301177 sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001178 ath9k_hw_set_interrupts(ah, sc->imask);
Sujithff37e332008-11-24 12:07:55 +05301179
Jouni Malinenbce048d2009-03-03 19:23:28 +02001180 ieee80211_wake_queues(hw);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001181
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001182 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Senthil Balasubramanian164ace32009-07-14 20:17:09 -04001183
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001184 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
1185 !ah->btcoex_hw.enabled) {
Luis R. Rodriguez5e197292009-09-09 15:15:55 -07001186 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1187 AR_STOMP_LOW_WLAN_WGHT);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001188 ath9k_hw_btcoex_enable(ah);
Vasanthakumar Thiagarajanf985ad12009-08-26 21:08:43 +05301189
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -07001190 if (common->bus_ops->bt_coex_prep)
1191 common->bus_ops->bt_coex_prep(common);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001192 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001193 ath9k_btcoex_timer_resume(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301194 }
1195
Sujith141b38b2009-02-04 08:10:07 +05301196mutex_unlock:
1197 mutex_unlock(&sc->mutex);
1198
Luis R. Rodriguezae8d2852008-12-23 15:58:40 -08001199 return r;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001200}
1201
1202static int ath9k_tx(struct ieee80211_hw *hw,
1203 struct sk_buff *skb)
1204{
Jouni Malinen147583c2008-08-11 14:01:50 +03001205 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Jouni Malinenbce048d2009-03-03 19:23:28 +02001206 struct ath_wiphy *aphy = hw->priv;
1207 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001208 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith528f0c62008-10-29 10:14:26 +05301209 struct ath_tx_control txctl;
Benoit Papillault1bc14882009-11-24 15:49:18 +01001210 int padpos, padsize;
1211 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
Sujith528f0c62008-10-29 10:14:26 +05301212
Jouni Malinen8089cc42009-03-03 19:23:38 +02001213 if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001214 ath_print(common, ATH_DBG_XMIT,
1215 "ath9k: %s: TX in unexpected wiphy state "
1216 "%d\n", wiphy_name(hw->wiphy), aphy->state);
Jouni Malinenee166a02009-03-03 19:23:36 +02001217 goto exit;
1218 }
1219
Gabor Juhos96148322009-07-24 17:27:21 +02001220 if (sc->ps_enabled) {
Jouni Malinendc8c4582009-05-19 17:01:42 +03001221 /*
1222 * mac80211 does not set PM field for normal data frames, so we
1223 * need to update that based on the current PS mode.
1224 */
1225 if (ieee80211_is_data(hdr->frame_control) &&
1226 !ieee80211_is_nullfunc(hdr->frame_control) &&
1227 !ieee80211_has_pm(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001228 ath_print(common, ATH_DBG_PS, "Add PM=1 for a TX frame "
1229 "while in PS mode\n");
Jouni Malinendc8c4582009-05-19 17:01:42 +03001230 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1231 }
1232 }
1233
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001234 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
1235 /*
1236 * We are using PS-Poll and mac80211 can request TX while in
1237 * power save mode. Need to wake up hardware for the TX to be
1238 * completed and if needed, also for RX of buffered frames.
1239 */
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001240 ath9k_ps_wakeup(sc);
1241 ath9k_hw_setrxabort(sc->sc_ah, 0);
1242 if (ieee80211_is_pspoll(hdr->frame_control)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001243 ath_print(common, ATH_DBG_PS,
1244 "Sending PS-Poll to pick a buffered frame\n");
Sujith1b04b932010-01-08 10:36:05 +05301245 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001246 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001247 ath_print(common, ATH_DBG_PS,
1248 "Wake up to complete TX\n");
Sujith1b04b932010-01-08 10:36:05 +05301249 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
Jouni Malinen9a23f9c2009-05-19 17:01:38 +03001250 }
1251 /*
1252 * The actual restore operation will happen only after
1253 * the sc_flags bit is cleared. We are just dropping
1254 * the ps_usecount here.
1255 */
1256 ath9k_ps_restore(sc);
1257 }
1258
Sujith528f0c62008-10-29 10:14:26 +05301259 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03001260
1261 /*
1262 * As a temporary workaround, assign seq# here; this will likely need
1263 * to be cleaned up to work better with Beacon transmission and virtual
1264 * BSSes.
1265 */
1266 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
Jouni Malinen147583c2008-08-11 14:01:50 +03001267 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Sujithb77f4832008-12-07 21:44:03 +05301268 sc->tx.seq_no += 0x10;
Jouni Malinen147583c2008-08-11 14:01:50 +03001269 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
Sujithb77f4832008-12-07 21:44:03 +05301270 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
Jouni Malinen147583c2008-08-11 14:01:50 +03001271 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001272
1273 /* Add the padding after the header if this is not already done */
Benoit Papillault1bc14882009-11-24 15:49:18 +01001274 padpos = ath9k_cmn_padpos(hdr->frame_control);
1275 padsize = padpos & 3;
1276 if (padsize && skb->len>padpos) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001277 if (skb_headroom(skb) < padsize)
1278 return -1;
1279 skb_push(skb, padsize);
Benoit Papillault1bc14882009-11-24 15:49:18 +01001280 memmove(skb->data, skb->data + padsize, padpos);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001281 }
1282
Sujith528f0c62008-10-29 10:14:26 +05301283 /* Check if a tx queue is available */
1284
1285 txctl.txq = ath_test_get_txq(sc, skb);
1286 if (!txctl.txq)
1287 goto exit;
1288
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001289 ath_print(common, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001291 if (ath_tx_start(hw, skb, &txctl) != 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001292 ath_print(common, ATH_DBG_XMIT, "TX failed\n");
Sujith528f0c62008-10-29 10:14:26 +05301293 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001294 }
1295
1296 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301297exit:
1298 dev_kfree_skb_any(skb);
1299 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001300}
1301
1302static void ath9k_stop(struct ieee80211_hw *hw)
1303{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001304 struct ath_wiphy *aphy = hw->priv;
1305 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001306 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001307 struct ath_common *common = ath9k_hw_common(ah);
Sujith9c84b792008-10-29 10:17:13 +05301308
Sujith4c483812009-08-18 10:51:52 +05301309 mutex_lock(&sc->mutex);
1310
Jouni Malinen9580a222009-03-03 19:23:33 +02001311 aphy->state = ATH_WIPHY_INACTIVE;
1312
Luis R. Rodriguezc94dbff2009-07-27 11:53:04 -07001313 cancel_delayed_work_sync(&sc->ath_led_blink_work);
1314 cancel_delayed_work_sync(&sc->tx_complete_work);
1315
1316 if (!sc->num_sec_wiphy) {
1317 cancel_delayed_work_sync(&sc->wiphy_work);
1318 cancel_work_sync(&sc->chan_work);
1319 }
1320
Sujith9c84b792008-10-29 10:17:13 +05301321 if (sc->sc_flags & SC_OP_INVALID) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001322 ath_print(common, ATH_DBG_ANY, "Device not present\n");
Sujith4c483812009-08-18 10:51:52 +05301323 mutex_unlock(&sc->mutex);
Sujith9c84b792008-10-29 10:17:13 +05301324 return;
1325 }
1326
Jouni Malinen9580a222009-03-03 19:23:33 +02001327 if (ath9k_wiphy_started(sc)) {
1328 mutex_unlock(&sc->mutex);
1329 return; /* another wiphy still in use */
1330 }
1331
Sujith3867cf62009-12-23 20:03:27 -05001332 /* Ensure HW is awake when we try to shut it down. */
1333 ath9k_ps_wakeup(sc);
1334
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001335 if (ah->btcoex_hw.enabled) {
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001336 ath9k_hw_btcoex_disable(ah);
Luis R. Rodriguez766ec4a2009-09-09 14:52:02 -07001337 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
Luis R. Rodriguez75d78392009-09-09 04:00:10 -07001338 ath9k_btcoex_timer_pause(sc);
Vasanthakumar Thiagarajan17739122009-08-26 21:08:50 +05301339 }
1340
Sujithff37e332008-11-24 12:07:55 +05301341 /* make sure h/w will not generate any interrupt
1342 * before setting the invalid flag. */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001343 ath9k_hw_set_interrupts(ah, 0);
Sujithff37e332008-11-24 12:07:55 +05301344
1345 if (!(sc->sc_flags & SC_OP_INVALID)) {
Sujith043a0402009-01-16 21:38:47 +05301346 ath_drain_all_txq(sc, false);
Sujithff37e332008-11-24 12:07:55 +05301347 ath_stoprecv(sc);
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001348 ath9k_hw_phy_disable(ah);
Sujithff37e332008-11-24 12:07:55 +05301349 } else
Sujithb77f4832008-12-07 21:44:03 +05301350 sc->rx.rxlink = NULL;
Sujithff37e332008-11-24 12:07:55 +05301351
Sujithff37e332008-11-24 12:07:55 +05301352 /* disable HAL and put h/w to sleep */
Luis R. Rodriguezaf03abe2009-09-09 02:33:11 -07001353 ath9k_hw_disable(ah);
1354 ath9k_hw_configpcipowersave(ah, 1, 1);
Sujith3867cf62009-12-23 20:03:27 -05001355 ath9k_ps_restore(sc);
1356
1357 /* Finally, put the chip in FULL SLEEP mode */
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001358 ath9k_setpower(sc, ATH9K_PM_FULL_SLEEP);
Sujithff37e332008-11-24 12:07:55 +05301359
1360 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361
Sujith141b38b2009-02-04 08:10:07 +05301362 mutex_unlock(&sc->mutex);
1363
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001364 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001365}
1366
1367static int ath9k_add_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001368 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001369{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001370 struct ath_wiphy *aphy = hw->priv;
1371 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001372 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001373 struct ath_vif *avp = (void *)vif->drv_priv;
Colin McCabed97809d2008-12-01 13:38:55 -08001374 enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001375 int ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001376
Sujith141b38b2009-02-04 08:10:07 +05301377 mutex_lock(&sc->mutex);
1378
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001379 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
1380 sc->nvifs > 0) {
1381 ret = -ENOBUFS;
1382 goto out;
1383 }
1384
Johannes Berg1ed32e42009-12-23 13:15:45 +01001385 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001386 case NL80211_IFTYPE_STATION:
Colin McCabed97809d2008-12-01 13:38:55 -08001387 ic_opmode = NL80211_IFTYPE_STATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001388 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001389 case NL80211_IFTYPE_ADHOC:
Johannes Berg05c914f2008-09-11 00:01:58 +02001390 case NL80211_IFTYPE_AP:
Pat Erley9cb54122009-03-20 22:59:59 -04001391 case NL80211_IFTYPE_MESH_POINT:
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001392 if (sc->nbcnvifs >= ATH_BCBUF) {
1393 ret = -ENOBUFS;
1394 goto out;
1395 }
Johannes Berg1ed32e42009-12-23 13:15:45 +01001396 ic_opmode = vif->type;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001397 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001398 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001399 ath_print(common, ATH_DBG_FATAL,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001400 "Interface type %d not yet supported\n", vif->type);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001401 ret = -EOPNOTSUPP;
1402 goto out;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001403 }
1404
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001405 ath_print(common, ATH_DBG_CONFIG,
1406 "Attach a VIF of type: %d\n", ic_opmode);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001407
Sujith17d79042009-02-09 13:27:03 +05301408 /* Set the VIF opmode */
Sujith5640b082008-10-29 10:16:06 +05301409 avp->av_opmode = ic_opmode;
1410 avp->av_bslot = -1;
1411
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001412 sc->nvifs++;
Jouni Malinen8ca21f02009-03-03 19:23:27 +02001413
1414 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
1415 ath9k_set_bssid_mask(hw);
1416
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001417 if (sc->nvifs > 1)
1418 goto out; /* skip global settings for secondary vif */
1419
Sujithb238e902009-03-03 10:16:56 +05301420 if (ic_opmode == NL80211_IFTYPE_AP) {
Sujith5640b082008-10-29 10:16:06 +05301421 ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
Sujithb238e902009-03-03 10:16:56 +05301422 sc->sc_flags |= SC_OP_TSF_RESET;
1423 }
Sujith5640b082008-10-29 10:16:06 +05301424
Sujith5640b082008-10-29 10:16:06 +05301425 /* Set the device opmode */
Sujith2660b812009-02-09 13:27:26 +05301426 sc->sc_ah->opmode = ic_opmode;
Sujith5640b082008-10-29 10:16:06 +05301427
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301428 /*
1429 * Enable MIB interrupts when there are hardware phy counters.
1430 * Note we only do this (at the moment) for station mode.
1431 */
Johannes Berg1ed32e42009-12-23 13:15:45 +01001432 if ((vif->type == NL80211_IFTYPE_STATION) ||
1433 (vif->type == NL80211_IFTYPE_ADHOC) ||
1434 (vif->type == NL80211_IFTYPE_MESH_POINT)) {
Sujith1aa8e842009-08-13 09:34:25 +05301435 sc->imask |= ATH9K_INT_MIB;
Sujith4af9cf42009-02-12 10:06:47 +05301436 sc->imask |= ATH9K_INT_TSFOOR;
1437 }
1438
Sujith17d79042009-02-09 13:27:03 +05301439 ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
Vivek Natarajan4e30ffa2009-01-28 20:53:27 +05301440
Johannes Berg1ed32e42009-12-23 13:15:45 +01001441 if (vif->type == NL80211_IFTYPE_AP ||
1442 vif->type == NL80211_IFTYPE_ADHOC ||
1443 vif->type == NL80211_IFTYPE_MONITOR)
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001444 ath_start_ani(common);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001445
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001446out:
Sujith141b38b2009-02-04 08:10:07 +05301447 mutex_unlock(&sc->mutex);
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001448 return ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001449}
1450
1451static void ath9k_remove_interface(struct ieee80211_hw *hw,
Johannes Berg1ed32e42009-12-23 13:15:45 +01001452 struct ieee80211_vif *vif)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001453{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001454 struct ath_wiphy *aphy = hw->priv;
1455 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001456 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berg1ed32e42009-12-23 13:15:45 +01001457 struct ath_vif *avp = (void *)vif->drv_priv;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001458 int i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001459
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001460 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001461
Sujith141b38b2009-02-04 08:10:07 +05301462 mutex_lock(&sc->mutex);
1463
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001464 /* Stop ANI */
Luis R. Rodriguez3d536ac2009-11-03 17:07:04 -08001465 del_timer_sync(&common->ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001466
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001467 /* Reclaim beacon resources */
Pat Erley9cb54122009-03-20 22:59:59 -04001468 if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
1469 (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
1470 (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001471 ath9k_ps_wakeup(sc);
Sujithb77f4832008-12-07 21:44:03 +05301472 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001473 ath_beacon_return(sc, avp);
Luis R. Rodriguez5f70a882009-12-23 20:03:28 -05001474 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001475 }
1476
Sujith672840a2008-08-11 14:05:08 +05301477 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001478
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001479 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
Johannes Berg1ed32e42009-12-23 13:15:45 +01001480 if (sc->beacon.bslot[i] == vif) {
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001481 printk(KERN_DEBUG "%s: vif had allocated beacon "
1482 "slot\n", __func__);
1483 sc->beacon.bslot[i] = NULL;
Jouni Malinenc52f33d2009-03-03 19:23:29 +02001484 sc->beacon.bslot_aphy[i] = NULL;
Jouni Malinen2c3db3d2009-03-03 19:23:26 +02001485 }
1486 }
1487
Sujith17d79042009-02-09 13:27:03 +05301488 sc->nvifs--;
Sujith141b38b2009-02-04 08:10:07 +05301489
1490 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001491}
1492
Johannes Berge8975582008-10-09 12:18:51 +02001493static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001494{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001495 struct ath_wiphy *aphy = hw->priv;
1496 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001497 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Johannes Berge8975582008-10-09 12:18:51 +02001498 struct ieee80211_conf *conf = &hw->conf;
Vivek Natarajan8782b412009-03-30 14:17:00 +05301499 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001500 bool disable_radio;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001501
Sujithaa33de02008-12-18 11:40:16 +05301502 mutex_lock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301503
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001504 /*
1505 * Leave this as the first check because we need to turn on the
1506 * radio if it was disabled before prior to processing the rest
1507 * of the changes. Likewise we must only disable the radio towards
1508 * the end.
1509 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001510 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001511 bool enable_radio;
1512 bool all_wiphys_idle;
1513 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001514
1515 spin_lock_bh(&sc->wiphy_lock);
1516 all_wiphys_idle = ath9k_all_wiphys_idle(sc);
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001517 ath9k_set_wiphy_idle(aphy, idle);
1518
1519 if (!idle && all_wiphys_idle)
1520 enable_radio = true;
1521
1522 /*
1523 * After we unlock here its possible another wiphy
1524 * can be re-renabled so to account for that we will
1525 * only disable the radio toward the end of this routine
1526 * if by then all wiphys are still idle.
1527 */
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001528 spin_unlock_bh(&sc->wiphy_lock);
1529
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001530 if (enable_radio) {
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001531 ath_radio_enable(sc, hw);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001532 ath_print(common, ATH_DBG_CONFIG,
1533 "not-idle: enabling radio\n");
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001534 }
1535 }
1536
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001537 /*
1538 * We just prepare to enable PS. We have to wait until our AP has
1539 * ACK'd our null data frame to disable RX otherwise we'll ignore
1540 * those ACKs and end up retransmitting the same null data frames.
1541 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1542 */
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301543 if (changed & IEEE80211_CONF_CHANGE_PS) {
1544 if (conf->flags & IEEE80211_CONF_PS) {
Sujith1b04b932010-01-08 10:36:05 +05301545 sc->ps_flags |= PS_ENABLED;
Vivek Natarajan8782b412009-03-30 14:17:00 +05301546 if (!(ah->caps.hw_caps &
1547 ATH9K_HW_CAP_AUTOSLEEP)) {
1548 if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
1549 sc->imask |= ATH9K_INT_TIM_TIMER;
1550 ath9k_hw_set_interrupts(sc->sc_ah,
1551 sc->imask);
1552 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301553 }
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001554 /*
1555 * At this point we know hardware has received an ACK
1556 * of a previously sent null data frame.
1557 */
Sujith1b04b932010-01-08 10:36:05 +05301558 if ((sc->ps_flags & PS_NULLFUNC_COMPLETED)) {
1559 sc->ps_flags &= ~PS_NULLFUNC_COMPLETED;
Luis R. Rodrigueze7824a52009-11-24 02:53:25 -05001560 sc->ps_enabled = true;
1561 ath9k_hw_setrxabort(sc->sc_ah, 1);
1562 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301563 } else {
Gabor Juhos96148322009-07-24 17:27:21 +02001564 sc->ps_enabled = false;
Sujith1b04b932010-01-08 10:36:05 +05301565 sc->ps_flags &= ~(PS_ENABLED |
1566 PS_NULLFUNC_COMPLETED);
Luis R. Rodriguez9ecdef42009-09-09 21:10:09 -07001567 ath9k_setpower(sc, ATH9K_PM_AWAKE);
Vivek Natarajan8782b412009-03-30 14:17:00 +05301568 if (!(ah->caps.hw_caps &
1569 ATH9K_HW_CAP_AUTOSLEEP)) {
1570 ath9k_hw_setrxabort(sc->sc_ah, 0);
Sujith1b04b932010-01-08 10:36:05 +05301571 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1572 PS_WAIT_FOR_CAB |
1573 PS_WAIT_FOR_PSPOLL_DATA |
1574 PS_WAIT_FOR_TX_ACK);
Vivek Natarajan8782b412009-03-30 14:17:00 +05301575 if (sc->imask & ATH9K_INT_TIM_TIMER) {
1576 sc->imask &= ~ATH9K_INT_TIM_TIMER;
1577 ath9k_hw_set_interrupts(sc->sc_ah,
1578 sc->imask);
1579 }
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301580 }
1581 }
1582 }
1583
Sujith199afd92010-01-08 10:36:13 +05301584 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1585 if (conf->flags & IEEE80211_CONF_MONITOR) {
1586 ath_print(common, ATH_DBG_CONFIG,
1587 "HW opmode set to Monitor mode\n");
1588 sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
1589 }
1590 }
1591
Johannes Berg47979382009-01-07 10:13:27 +01001592 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Sujith99405f92008-11-24 12:08:35 +05301593 struct ieee80211_channel *curchan = hw->conf.channel;
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001594 int pos = curchan->hw_value;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001595
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001596 aphy->chan_idx = pos;
1597 aphy->chan_is_ht = conf_is_ht(conf);
1598
Jouni Malinen8089cc42009-03-03 19:23:38 +02001599 if (aphy->state == ATH_WIPHY_SCAN ||
1600 aphy->state == ATH_WIPHY_ACTIVE)
1601 ath9k_wiphy_pause_all_forced(sc, aphy);
1602 else {
1603 /*
1604 * Do not change operational channel based on a paused
1605 * wiphy changes.
1606 */
1607 goto skip_chan_change;
1608 }
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001609
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001610 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1611 curchan->center_freq);
Johannes Bergae5eb022008-10-14 16:58:37 +02001612
Luis R. Rodriguez5f8e0772009-01-22 15:16:48 -08001613 /* XXX: remove me eventualy */
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001614 ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
Sujithe11602b2008-11-27 09:46:27 +05301615
Luis R. Rodriguezecf70442008-12-23 15:58:43 -08001616 ath_update_chainmask(sc, conf_is_ht(conf));
Sujith86060f02009-01-07 14:25:29 +05301617
Jouni Malinen0e2dedf2009-03-03 19:23:32 +02001618 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001619 ath_print(common, ATH_DBG_FATAL,
1620 "Unable to set channel\n");
Sujithaa33de02008-12-18 11:40:16 +05301621 mutex_unlock(&sc->mutex);
Sujithe11602b2008-11-27 09:46:27 +05301622 return -EINVAL;
1623 }
Sujith094d05d2008-12-12 11:57:43 +05301624 }
Sujith86b89ee2008-08-07 10:54:57 +05301625
Jouni Malinen8089cc42009-03-03 19:23:38 +02001626skip_chan_change:
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001627 if (changed & IEEE80211_CONF_CHANGE_POWER) {
Sujith17d79042009-02-09 13:27:03 +05301628 sc->config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezc9f6a652010-01-19 14:04:19 -05001629 ath_update_txpow(sc);
1630 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001631
Luis R. Rodriguez194b7c12009-10-29 10:41:15 -07001632 spin_lock_bh(&sc->wiphy_lock);
1633 disable_radio = ath9k_all_wiphys_idle(sc);
1634 spin_unlock_bh(&sc->wiphy_lock);
1635
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001636 if (disable_radio) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001637 ath_print(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
Luis R. Rodriguez68a89112009-11-02 14:35:42 -08001638 ath_radio_disable(sc, hw);
Luis R. Rodriguez64839172009-07-14 20:22:53 -04001639 }
1640
Sujithaa33de02008-12-18 11:40:16 +05301641 mutex_unlock(&sc->mutex);
Sujith141b38b2009-02-04 08:10:07 +05301642
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001643 return 0;
1644}
1645
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001646#define SUPPORTED_FILTERS \
1647 (FIF_PROMISC_IN_BSS | \
1648 FIF_ALLMULTI | \
1649 FIF_CONTROL | \
Luis R. Rodriguezaf6a3fc2009-08-08 21:55:16 -04001650 FIF_PSPOLL | \
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001651 FIF_OTHER_BSS | \
1652 FIF_BCN_PRBRESP_PROMISC | \
1653 FIF_FCSFAIL)
1654
Sujith7dcfdcd2008-08-11 14:03:13 +05301655/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001656static void ath9k_configure_filter(struct ieee80211_hw *hw,
1657 unsigned int changed_flags,
1658 unsigned int *total_flags,
Johannes Berg3ac64be2009-08-17 16:16:53 +02001659 u64 multicast)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001660{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001661 struct ath_wiphy *aphy = hw->priv;
1662 struct ath_softc *sc = aphy->sc;
Sujith7dcfdcd2008-08-11 14:03:13 +05301663 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001664
1665 changed_flags &= SUPPORTED_FILTERS;
1666 *total_flags &= SUPPORTED_FILTERS;
1667
Sujithb77f4832008-12-07 21:44:03 +05301668 sc->rx.rxfilter = *total_flags;
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001669 ath9k_ps_wakeup(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301670 rfilt = ath_calcrxfilter(sc);
1671 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
Jouni Malinenaa68aea2009-05-19 17:01:41 +03001672 ath9k_ps_restore(sc);
Sujith7dcfdcd2008-08-11 14:03:13 +05301673
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001674 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_CONFIG,
1675 "Set HW RX filter: 0x%x\n", rfilt);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001676}
1677
1678static void ath9k_sta_notify(struct ieee80211_hw *hw,
1679 struct ieee80211_vif *vif,
1680 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02001681 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001682{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001683 struct ath_wiphy *aphy = hw->priv;
1684 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001685
1686 switch (cmd) {
1687 case STA_NOTIFY_ADD:
Sujith5640b082008-10-29 10:16:06 +05301688 ath_node_attach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001689 break;
1690 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05301691 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001692 break;
1693 default:
1694 break;
1695 }
1696}
1697
Sujith141b38b2009-02-04 08:10:07 +05301698static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001699 const struct ieee80211_tx_queue_params *params)
1700{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001701 struct ath_wiphy *aphy = hw->priv;
1702 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001703 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujithea9880f2008-08-07 10:53:10 +05301704 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001705 int ret = 0, qnum;
1706
1707 if (queue >= WME_NUM_AC)
1708 return 0;
1709
Sujith141b38b2009-02-04 08:10:07 +05301710 mutex_lock(&sc->mutex);
1711
Sujith1ffb0612009-03-30 15:28:46 +05301712 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1713
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001714 qi.tqi_aifs = params->aifs;
1715 qi.tqi_cwmin = params->cw_min;
1716 qi.tqi_cwmax = params->cw_max;
1717 qi.tqi_burstTime = params->txop;
1718 qnum = ath_get_hal_qnum(queue, sc);
1719
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001720 ath_print(common, ATH_DBG_CONFIG,
1721 "Configure tx [queue/halq] [%d/%d], "
1722 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1723 queue, qnum, params->aifs, params->cw_min,
1724 params->cw_max, params->txop);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001725
1726 ret = ath_txq_update(sc, qnum, &qi);
1727 if (ret)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001728 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001729
Vivek Natarajan94db2932009-11-25 12:01:54 +05301730 if (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC)
1731 if ((qnum == sc->tx.hwq_map[ATH9K_WME_AC_BE]) && !ret)
1732 ath_beaconq_config(sc);
1733
Sujith141b38b2009-02-04 08:10:07 +05301734 mutex_unlock(&sc->mutex);
1735
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736 return ret;
1737}
1738
1739static int ath9k_set_key(struct ieee80211_hw *hw,
1740 enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01001741 struct ieee80211_vif *vif,
1742 struct ieee80211_sta *sta,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001743 struct ieee80211_key_conf *key)
1744{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001745 struct ath_wiphy *aphy = hw->priv;
1746 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001747 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001748 int ret = 0;
1749
Jouni Malinenb3bd89c2009-02-24 13:42:01 +02001750 if (modparam_nohwcrypt)
1751 return -ENOSPC;
1752
Sujith141b38b2009-02-04 08:10:07 +05301753 mutex_lock(&sc->mutex);
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301754 ath9k_ps_wakeup(sc);
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001755 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001756
1757 switch (cmd) {
1758 case SET_KEY:
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -08001759 ret = ath_key_config(common, vif, sta, key);
Jouni Malinen6ace2892008-12-17 13:32:17 +02001760 if (ret >= 0) {
1761 key->hw_key_idx = ret;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001762 /* push IV and Michael MIC generation to stack */
1763 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301764 if (key->alg == ALG_TKIP)
1765 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Jouni Malinen0ced0e12009-01-08 13:32:13 +02001766 if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1767 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
Jouni Malinen6ace2892008-12-17 13:32:17 +02001768 ret = 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769 }
1770 break;
1771 case DISABLE_KEY:
Luis R. Rodriguez7e86c102009-11-04 17:21:01 -08001772 ath_key_delete(common, key);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001773 break;
1774 default:
1775 ret = -EINVAL;
1776 }
1777
Vivek Natarajan3cbb5dd2009-01-20 11:17:08 +05301778 ath9k_ps_restore(sc);
Sujith141b38b2009-02-04 08:10:07 +05301779 mutex_unlock(&sc->mutex);
1780
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001781 return ret;
1782}
1783
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001784static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1785 struct ieee80211_vif *vif,
1786 struct ieee80211_bss_conf *bss_conf,
1787 u32 changed)
1788{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001789 struct ath_wiphy *aphy = hw->priv;
1790 struct ath_softc *sc = aphy->sc;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001791 struct ath_hw *ah = sc->sc_ah;
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001792 struct ath_common *common = ath9k_hw_common(ah);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001793 struct ath_vif *avp = (void *)vif->drv_priv;
Felix Fietkau0005baf2010-01-15 02:33:40 +01001794 int slottime;
Sujithc6089cc2009-11-16 11:40:48 +05301795 int error;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001796
Sujith141b38b2009-02-04 08:10:07 +05301797 mutex_lock(&sc->mutex);
1798
Sujithc6089cc2009-11-16 11:40:48 +05301799 if (changed & BSS_CHANGED_BSSID) {
1800 /* Set BSSID */
1801 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1802 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
Luis R. Rodriguez15107182009-09-10 09:22:37 -07001803 common->curaid = 0;
Luis R. Rodriguezf2b21432009-09-10 08:50:20 -07001804 ath9k_hw_write_associd(ah);
Sujithc6089cc2009-11-16 11:40:48 +05301805
1806 /* Set aggregation protection mode parameters */
1807 sc->config.ath_aggr_prot = 0;
1808
1809 /* Only legacy IBSS for now */
1810 if (vif->type == NL80211_IFTYPE_ADHOC)
1811 ath_update_chainmask(sc, 0);
1812
1813 ath_print(common, ATH_DBG_CONFIG,
1814 "BSSID: %pM aid: 0x%x\n",
1815 common->curbssid, common->curaid);
1816
1817 /* need to reconfigure the beacon */
1818 sc->sc_flags &= ~SC_OP_BEACONS ;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001819 }
1820
Sujithc6089cc2009-11-16 11:40:48 +05301821 /* Enable transmission of beacons (AP, IBSS, MESH) */
1822 if ((changed & BSS_CHANGED_BEACON) ||
1823 ((changed & BSS_CHANGED_BEACON_ENABLED) && bss_conf->enable_beacon)) {
1824 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1825 error = ath_beacon_alloc(aphy, vif);
1826 if (!error)
1827 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001828 }
1829
Felix Fietkau0005baf2010-01-15 02:33:40 +01001830 if (changed & BSS_CHANGED_ERP_SLOT) {
1831 if (bss_conf->use_short_slot)
1832 slottime = 9;
1833 else
1834 slottime = 20;
1835 if (vif->type == NL80211_IFTYPE_AP) {
1836 /*
1837 * Defer update, so that connected stations can adjust
1838 * their settings at the same time.
1839 * See beacon.c for more details
1840 */
1841 sc->beacon.slottime = slottime;
1842 sc->beacon.updateslot = UPDATE;
1843 } else {
1844 ah->slottime = slottime;
1845 ath9k_hw_init_global_settings(ah);
1846 }
1847 }
1848
Sujithc6089cc2009-11-16 11:40:48 +05301849 /* Disable transmission of beacons */
1850 if ((changed & BSS_CHANGED_BEACON_ENABLED) && !bss_conf->enable_beacon)
1851 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
1852
1853 if (changed & BSS_CHANGED_BEACON_INT) {
1854 sc->beacon_interval = bss_conf->beacon_int;
1855 /*
1856 * In case of AP mode, the HW TSF has to be reset
1857 * when the beacon interval changes.
1858 */
1859 if (vif->type == NL80211_IFTYPE_AP) {
1860 sc->sc_flags |= SC_OP_TSF_RESET;
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001861 ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001862 error = ath_beacon_alloc(aphy, vif);
1863 if (!error)
1864 ath_beacon_config(sc, vif);
Sujithc6089cc2009-11-16 11:40:48 +05301865 } else {
1866 ath_beacon_config(sc, vif);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001867 }
1868 }
1869
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001870 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001871 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1872 bss_conf->use_short_preamble);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001873 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05301874 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001875 else
Sujith672840a2008-08-11 14:05:08 +05301876 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001877 }
1878
1879 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001880 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1881 bss_conf->use_cts_prot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001882 if (bss_conf->use_cts_prot &&
1883 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05301884 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001885 else
Sujith672840a2008-08-11 14:05:08 +05301886 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001887 }
1888
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001889 if (changed & BSS_CHANGED_ASSOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001890 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001891 bss_conf->assoc);
Sujith5640b082008-10-29 10:16:06 +05301892 ath9k_bss_assoc_info(sc, vif, bss_conf);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001893 }
Sujith141b38b2009-02-04 08:10:07 +05301894
1895 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001896}
1897
1898static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
1899{
1900 u64 tsf;
Jouni Malinenbce048d2009-03-03 19:23:28 +02001901 struct ath_wiphy *aphy = hw->priv;
1902 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001903
Sujith141b38b2009-02-04 08:10:07 +05301904 mutex_lock(&sc->mutex);
1905 tsf = ath9k_hw_gettsf64(sc->sc_ah);
1906 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001907
1908 return tsf;
1909}
1910
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001911static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1912{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001913 struct ath_wiphy *aphy = hw->priv;
1914 struct ath_softc *sc = aphy->sc;
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001915
Sujith141b38b2009-02-04 08:10:07 +05301916 mutex_lock(&sc->mutex);
1917 ath9k_hw_settsf64(sc->sc_ah, tsf);
1918 mutex_unlock(&sc->mutex);
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01001919}
1920
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001921static void ath9k_reset_tsf(struct ieee80211_hw *hw)
1922{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001923 struct ath_wiphy *aphy = hw->priv;
1924 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001925
Sujith141b38b2009-02-04 08:10:07 +05301926 mutex_lock(&sc->mutex);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001927
1928 ath9k_ps_wakeup(sc);
Sujith141b38b2009-02-04 08:10:07 +05301929 ath9k_hw_reset_tsf(sc->sc_ah);
Luis R. Rodriguez21526d52009-09-09 20:05:39 -07001930 ath9k_ps_restore(sc);
1931
Sujith141b38b2009-02-04 08:10:07 +05301932 mutex_unlock(&sc->mutex);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001933}
1934
1935static int ath9k_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01001936 struct ieee80211_vif *vif,
Sujith141b38b2009-02-04 08:10:07 +05301937 enum ieee80211_ampdu_mlme_action action,
1938 struct ieee80211_sta *sta,
1939 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001940{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001941 struct ath_wiphy *aphy = hw->priv;
1942 struct ath_softc *sc = aphy->sc;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001943 int ret = 0;
1944
1945 switch (action) {
1946 case IEEE80211_AMPDU_RX_START:
Sujithdca3edb2008-10-29 10:19:01 +05301947 if (!(sc->sc_flags & SC_OP_RXAGGR))
1948 ret = -ENOTSUPP;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001949 break;
1950 case IEEE80211_AMPDU_RX_STOP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001951 break;
1952 case IEEE80211_AMPDU_TX_START:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001953 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301954 ath_tx_aggr_start(sc, sta, tid, ssn);
Johannes Bergc951ad32009-11-16 12:00:38 +01001955 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001956 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001957 break;
1958 case IEEE80211_AMPDU_TX_STOP:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001959 ath9k_ps_wakeup(sc);
Sujithf83da962009-07-23 15:32:37 +05301960 ath_tx_aggr_stop(sc, sta, tid);
Johannes Bergc951ad32009-11-16 12:00:38 +01001961 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001962 ath9k_ps_restore(sc);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001963 break;
Johannes Bergb1720232009-03-23 17:28:39 +01001964 case IEEE80211_AMPDU_TX_OPERATIONAL:
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001965 ath9k_ps_wakeup(sc);
Sujith8469cde2008-10-29 10:19:28 +05301966 ath_tx_aggr_resume(sc, sta, tid);
Luis R. Rodriguez8b685ba2009-12-23 20:03:29 -05001967 ath9k_ps_restore(sc);
Sujith8469cde2008-10-29 10:19:28 +05301968 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001969 default:
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001970 ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
1971 "Unknown AMPDU action\n");
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001972 }
1973
1974 return ret;
1975}
1976
Sujith0c98de62009-03-03 10:16:45 +05301977static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
1978{
Jouni Malinenbce048d2009-03-03 19:23:28 +02001979 struct ath_wiphy *aphy = hw->priv;
1980 struct ath_softc *sc = aphy->sc;
Sujith05c78d62009-12-14 14:57:04 +05301981 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith0c98de62009-03-03 10:16:45 +05301982
Sujith3d832612009-08-21 12:00:28 +05301983 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02001984 if (ath9k_wiphy_scanning(sc)) {
1985 printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
1986 "same time\n");
1987 /*
1988 * Do not allow the concurrent scanning state for now. This
1989 * could be improved with scanning control moved into ath9k.
1990 */
Sujith3d832612009-08-21 12:00:28 +05301991 mutex_unlock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02001992 return;
1993 }
1994
1995 aphy->state = ATH_WIPHY_SCAN;
1996 ath9k_wiphy_pause_all_forced(sc, aphy);
Sujith0c98de62009-03-03 10:16:45 +05301997 sc->sc_flags |= SC_OP_SCANNING;
Sujith05c78d62009-12-14 14:57:04 +05301998 del_timer_sync(&common->ani.timer);
Sujithb6ce5c32009-12-14 14:57:06 +05301999 cancel_delayed_work_sync(&sc->tx_complete_work);
Sujith3d832612009-08-21 12:00:28 +05302000 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302001}
2002
2003static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2004{
Jouni Malinenbce048d2009-03-03 19:23:28 +02002005 struct ath_wiphy *aphy = hw->priv;
2006 struct ath_softc *sc = aphy->sc;
Sujith05c78d62009-12-14 14:57:04 +05302007 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Sujith0c98de62009-03-03 10:16:45 +05302008
Sujith3d832612009-08-21 12:00:28 +05302009 mutex_lock(&sc->mutex);
Jouni Malinen8089cc42009-03-03 19:23:38 +02002010 aphy->state = ATH_WIPHY_ACTIVE;
Sujith0c98de62009-03-03 10:16:45 +05302011 sc->sc_flags &= ~SC_OP_SCANNING;
Sujith9c07a772009-04-13 21:56:36 +05302012 sc->sc_flags |= SC_OP_FULL_RESET;
Sujith05c78d62009-12-14 14:57:04 +05302013 ath_start_ani(common);
Sujithb6ce5c32009-12-14 14:57:06 +05302014 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
Vivek Natarajand0bec342009-09-02 15:50:55 +05302015 ath_beacon_config(sc, NULL);
Sujith3d832612009-08-21 12:00:28 +05302016 mutex_unlock(&sc->mutex);
Sujith0c98de62009-03-03 10:16:45 +05302017}
2018
Felix Fietkaue239d852010-01-15 02:34:58 +01002019static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
2020{
2021 struct ath_wiphy *aphy = hw->priv;
2022 struct ath_softc *sc = aphy->sc;
2023 struct ath_hw *ah = sc->sc_ah;
2024
2025 mutex_lock(&sc->mutex);
2026 ah->coverage_class = coverage_class;
2027 ath9k_hw_init_global_settings(ah);
2028 mutex_unlock(&sc->mutex);
2029}
2030
Gabor Juhos6baff7f2009-01-14 20:17:06 +01002031struct ieee80211_ops ath9k_ops = {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002032 .tx = ath9k_tx,
2033 .start = ath9k_start,
2034 .stop = ath9k_stop,
2035 .add_interface = ath9k_add_interface,
2036 .remove_interface = ath9k_remove_interface,
2037 .config = ath9k_config,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002038 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002039 .sta_notify = ath9k_sta_notify,
2040 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002041 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002042 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002043 .get_tsf = ath9k_get_tsf,
Alina Friedrichsen3b5d6652009-01-24 07:09:59 +01002044 .set_tsf = ath9k_set_tsf,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002045 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02002046 .ampdu_action = ath9k_ampdu_action,
Sujith0c98de62009-03-03 10:16:45 +05302047 .sw_scan_start = ath9k_sw_scan_start,
2048 .sw_scan_complete = ath9k_sw_scan_complete,
Johannes Berg3b319aa2009-06-13 14:50:26 +05302049 .rfkill_poll = ath9k_rfkill_poll_state,
Felix Fietkaue239d852010-01-15 02:34:58 +01002050 .set_coverage_class = ath9k_set_coverage_class,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07002051};