Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 3 | * |
| 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. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 17 | #include <linux/nl80211.h> |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 18 | #include <linux/delay.h> |
Sujith | 394cf0a | 2009-02-09 13:26:54 +0530 | [diff] [blame] | 19 | #include "ath9k.h" |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 20 | #include "btcoex.h" |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 21 | |
Sujith Manoharan | 6dcc344 | 2012-07-17 17:16:36 +0530 | [diff] [blame] | 22 | static void ath9k_set_assoc_state(struct ath_softc *sc, |
| 23 | struct ieee80211_vif *vif); |
| 24 | |
Sven Eckelmann | 313eb87 | 2012-06-25 07:15:22 +0200 | [diff] [blame] | 25 | u8 ath9k_parse_mpdudensity(u8 mpdudensity) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 26 | { |
| 27 | /* |
| 28 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 29 | * 0 for no restriction |
| 30 | * 1 for 1/4 us |
| 31 | * 2 for 1/2 us |
| 32 | * 3 for 1 us |
| 33 | * 4 for 2 us |
| 34 | * 5 for 4 us |
| 35 | * 6 for 8 us |
| 36 | * 7 for 16 us |
| 37 | */ |
| 38 | switch (mpdudensity) { |
| 39 | case 0: |
| 40 | return 0; |
| 41 | case 1: |
| 42 | case 2: |
| 43 | case 3: |
| 44 | /* Our lower layer calculations limit our precision to |
| 45 | 1 microsecond */ |
| 46 | return 1; |
| 47 | case 4: |
| 48 | return 2; |
| 49 | case 5: |
| 50 | return 4; |
| 51 | case 6: |
| 52 | return 8; |
| 53 | case 7: |
| 54 | return 16; |
| 55 | default: |
| 56 | return 0; |
| 57 | } |
| 58 | } |
| 59 | |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 60 | static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq) |
| 61 | { |
| 62 | bool pending = false; |
| 63 | |
| 64 | spin_lock_bh(&txq->axq_lock); |
| 65 | |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 66 | if (txq->axq_depth) |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 67 | pending = true; |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 68 | |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 69 | if (txq->mac80211_qnum >= 0) { |
| 70 | struct list_head *list; |
| 71 | |
| 72 | list = &sc->cur_chan->acq[txq->mac80211_qnum]; |
| 73 | if (!list_empty(list)) |
| 74 | pending = true; |
| 75 | } |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 76 | spin_unlock_bh(&txq->axq_lock); |
| 77 | return pending; |
| 78 | } |
| 79 | |
Mohammed Shafi Shajakhan | 6d79cb4 | 2011-05-19 17:40:46 +0530 | [diff] [blame] | 80 | static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode) |
Luis R. Rodriguez | 8c77a56 | 2009-09-09 21:02:34 -0700 | [diff] [blame] | 81 | { |
| 82 | unsigned long flags; |
| 83 | bool ret; |
| 84 | |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 85 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 86 | ret = ath9k_hw_setpower(sc->sc_ah, mode); |
| 87 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Luis R. Rodriguez | 8c77a56 | 2009-09-09 21:02:34 -0700 | [diff] [blame] | 88 | |
| 89 | return ret; |
| 90 | } |
| 91 | |
Felix Fietkau | bf3dac5 | 2013-11-11 22:23:33 +0100 | [diff] [blame] | 92 | void ath_ps_full_sleep(unsigned long data) |
| 93 | { |
| 94 | struct ath_softc *sc = (struct ath_softc *) data; |
| 95 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 96 | bool reset; |
| 97 | |
| 98 | spin_lock(&common->cc_lock); |
| 99 | ath_hw_cycle_counters_update(common); |
| 100 | spin_unlock(&common->cc_lock); |
| 101 | |
| 102 | ath9k_hw_setrxabort(sc->sc_ah, 1); |
| 103 | ath9k_hw_stopdmarecv(sc->sc_ah, &reset); |
| 104 | |
| 105 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); |
| 106 | } |
| 107 | |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 108 | void ath9k_ps_wakeup(struct ath_softc *sc) |
| 109 | { |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 110 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 111 | unsigned long flags; |
Felix Fietkau | fbb078f | 2010-11-03 01:36:51 +0100 | [diff] [blame] | 112 | enum ath9k_power_mode power_mode; |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 113 | |
| 114 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 115 | if (++sc->ps_usecount != 1) |
| 116 | goto unlock; |
| 117 | |
Felix Fietkau | bf3dac5 | 2013-11-11 22:23:33 +0100 | [diff] [blame] | 118 | del_timer_sync(&sc->sleep_timer); |
Felix Fietkau | fbb078f | 2010-11-03 01:36:51 +0100 | [diff] [blame] | 119 | power_mode = sc->sc_ah->power_mode; |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 120 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 121 | |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 122 | /* |
| 123 | * While the hardware is asleep, the cycle counters contain no |
| 124 | * useful data. Better clear them now so that they don't mess up |
| 125 | * survey data results. |
| 126 | */ |
Felix Fietkau | fbb078f | 2010-11-03 01:36:51 +0100 | [diff] [blame] | 127 | if (power_mode != ATH9K_PM_AWAKE) { |
| 128 | spin_lock(&common->cc_lock); |
| 129 | ath_hw_cycle_counters_update(common); |
| 130 | memset(&common->cc_survey, 0, sizeof(common->cc_survey)); |
Rajkumar Manoharan | c9ae6ab | 2012-06-04 16:28:41 +0530 | [diff] [blame] | 131 | memset(&common->cc_ani, 0, sizeof(common->cc_ani)); |
Felix Fietkau | fbb078f | 2010-11-03 01:36:51 +0100 | [diff] [blame] | 132 | spin_unlock(&common->cc_lock); |
| 133 | } |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 134 | |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 135 | unlock: |
| 136 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 137 | } |
| 138 | |
| 139 | void ath9k_ps_restore(struct ath_softc *sc) |
| 140 | { |
Felix Fietkau | 898c914 | 2010-10-12 14:02:53 +0200 | [diff] [blame] | 141 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | c6c539f | 2011-09-14 21:24:24 +0200 | [diff] [blame] | 142 | enum ath9k_power_mode mode; |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 143 | unsigned long flags; |
| 144 | |
| 145 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 146 | if (--sc->ps_usecount != 0) |
| 147 | goto unlock; |
| 148 | |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 149 | if (sc->ps_idle) { |
Felix Fietkau | bf3dac5 | 2013-11-11 22:23:33 +0100 | [diff] [blame] | 150 | mod_timer(&sc->sleep_timer, jiffies + HZ / 10); |
| 151 | goto unlock; |
| 152 | } |
| 153 | |
| 154 | if (sc->ps_enabled && |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 155 | !(sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 156 | PS_WAIT_FOR_CAB | |
| 157 | PS_WAIT_FOR_PSPOLL_DATA | |
Rajkumar Manoharan | 424749c | 2012-10-10 23:03:02 +0530 | [diff] [blame] | 158 | PS_WAIT_FOR_TX_ACK | |
| 159 | PS_WAIT_FOR_ANI))) { |
Felix Fietkau | c6c539f | 2011-09-14 21:24:24 +0200 | [diff] [blame] | 160 | mode = ATH9K_PM_NETWORK_SLEEP; |
Rajkumar Manoharan | 08d4df4 | 2012-07-01 19:53:54 +0530 | [diff] [blame] | 161 | if (ath9k_hw_btcoex_is_enabled(sc->sc_ah)) |
| 162 | ath9k_btcoex_stop_gen_timer(sc); |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 163 | } else { |
Felix Fietkau | c6c539f | 2011-09-14 21:24:24 +0200 | [diff] [blame] | 164 | goto unlock; |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 165 | } |
Felix Fietkau | c6c539f | 2011-09-14 21:24:24 +0200 | [diff] [blame] | 166 | |
| 167 | spin_lock(&common->cc_lock); |
| 168 | ath_hw_cycle_counters_update(common); |
| 169 | spin_unlock(&common->cc_lock); |
| 170 | |
Felix Fietkau | 1a8f0d39 | 2011-09-22 08:04:32 -0600 | [diff] [blame] | 171 | ath9k_hw_setpower(sc->sc_ah, mode); |
Luis R. Rodriguez | a91d75ae | 2009-09-09 20:29:18 -0700 | [diff] [blame] | 172 | |
| 173 | unlock: |
| 174 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 175 | } |
| 176 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 177 | static void __ath_cancel_work(struct ath_softc *sc) |
| 178 | { |
| 179 | cancel_work_sync(&sc->paprd_work); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 180 | cancel_delayed_work_sync(&sc->tx_complete_work); |
| 181 | cancel_delayed_work_sync(&sc->hw_pll_work); |
Sujith Manoharan | fad29cd | 2012-06-25 13:54:22 +0530 | [diff] [blame] | 182 | |
Sujith Manoharan | bf52592 | 2012-06-27 14:15:59 +0530 | [diff] [blame] | 183 | #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT |
Sujith Manoharan | fad29cd | 2012-06-25 13:54:22 +0530 | [diff] [blame] | 184 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 185 | cancel_work_sync(&sc->mci_work); |
Sujith Manoharan | bf52592 | 2012-06-27 14:15:59 +0530 | [diff] [blame] | 186 | #endif |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Sujith Manoharan | e60001e | 2013-10-28 12:22:04 +0530 | [diff] [blame] | 189 | void ath_cancel_work(struct ath_softc *sc) |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 190 | { |
| 191 | __ath_cancel_work(sc); |
| 192 | cancel_work_sync(&sc->hw_reset_work); |
| 193 | } |
| 194 | |
Sujith Manoharan | e60001e | 2013-10-28 12:22:04 +0530 | [diff] [blame] | 195 | void ath_restart_work(struct ath_softc *sc) |
Sujith Manoharan | af68aba | 2012-06-04 20:23:43 +0530 | [diff] [blame] | 196 | { |
Sujith Manoharan | af68aba | 2012-06-04 20:23:43 +0530 | [diff] [blame] | 197 | ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0); |
| 198 | |
Sujith Manoharan | 19c3616 | 2013-08-20 10:05:59 +0530 | [diff] [blame] | 199 | if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah)) |
Sujith Manoharan | af68aba | 2012-06-04 20:23:43 +0530 | [diff] [blame] | 200 | ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, |
| 201 | msecs_to_jiffies(ATH_PLL_WORK_INTERVAL)); |
| 202 | |
Sujith Manoharan | da0d45f | 2012-07-17 17:16:29 +0530 | [diff] [blame] | 203 | ath_start_ani(sc); |
Sujith Manoharan | af68aba | 2012-06-04 20:23:43 +0530 | [diff] [blame] | 204 | } |
| 205 | |
John W. Linville | 9ebea38 | 2013-01-28 13:54:03 -0500 | [diff] [blame] | 206 | static bool ath_prepare_reset(struct ath_softc *sc) |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 207 | { |
| 208 | struct ath_hw *ah = sc->sc_ah; |
Felix Fietkau | ceea2a5 | 2012-05-24 14:32:19 +0200 | [diff] [blame] | 209 | bool ret = true; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 210 | |
| 211 | ieee80211_stop_queues(sc->hw); |
Sujith Manoharan | da0d45f | 2012-07-17 17:16:29 +0530 | [diff] [blame] | 212 | ath_stop_ani(sc); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 213 | ath9k_hw_disable_interrupts(ah); |
| 214 | |
Felix Fietkau | 1381559 | 2013-01-20 18:51:53 +0100 | [diff] [blame] | 215 | if (!ath_drain_all_txq(sc)) |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 216 | ret = false; |
| 217 | |
Felix Fietkau | 0a62acb | 2013-01-20 18:51:52 +0100 | [diff] [blame] | 218 | if (!ath_stoprecv(sc)) |
Felix Fietkau | ceea2a5 | 2012-05-24 14:32:19 +0200 | [diff] [blame] | 219 | ret = false; |
| 220 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | static bool ath_complete_reset(struct ath_softc *sc, bool start) |
| 225 | { |
| 226 | struct ath_hw *ah = sc->sc_ah; |
| 227 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith Manoharan | 196fb86 | 2012-06-04 20:24:13 +0530 | [diff] [blame] | 228 | unsigned long flags; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 229 | |
| 230 | if (ath_startrecv(sc) != 0) { |
| 231 | ath_err(common, "Unable to restart recv logic\n"); |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | ath9k_cmn_update_txpow(ah, sc->curtxpow, |
Felix Fietkau | bc7e1be | 2014-06-11 16:17:50 +0530 | [diff] [blame] | 236 | sc->cur_chan->txpower, &sc->curtxpow); |
Sujith Manoharan | b74713d | 2012-06-04 20:24:01 +0530 | [diff] [blame] | 237 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 238 | clear_bit(ATH_OP_HW_RESET, &common->op_flags); |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 239 | ath9k_hw_set_interrupts(ah); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 240 | ath9k_hw_enable_interrupts(ah); |
| 241 | |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 242 | if (!sc->cur_chan->offchannel && start) { |
Felix Fietkau | 8d7e09d | 2014-06-11 16:18:01 +0530 | [diff] [blame] | 243 | /* restore per chanctx TSF timer */ |
| 244 | if (sc->cur_chan->tsf_val) { |
| 245 | u32 offset; |
| 246 | |
| 247 | offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, |
| 248 | NULL); |
| 249 | ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset); |
| 250 | } |
| 251 | |
| 252 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 253 | if (!test_bit(ATH_OP_BEACONS, &common->op_flags)) |
Sujith Manoharan | 196fb86 | 2012-06-04 20:24:13 +0530 | [diff] [blame] | 254 | goto work; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 255 | |
Sujith Manoharan | 196fb86 | 2012-06-04 20:24:13 +0530 | [diff] [blame] | 256 | if (ah->opmode == NL80211_IFTYPE_STATION && |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 257 | test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) { |
Sujith Manoharan | 196fb86 | 2012-06-04 20:24:13 +0530 | [diff] [blame] | 258 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 259 | sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; |
| 260 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Sujith Manoharan | a676828 | 2013-05-06 10:09:03 +0530 | [diff] [blame] | 261 | } else { |
| 262 | ath9k_set_beacon(sc); |
Sujith Manoharan | 196fb86 | 2012-06-04 20:24:13 +0530 | [diff] [blame] | 263 | } |
| 264 | work: |
Sujith Manoharan | af68aba | 2012-06-04 20:23:43 +0530 | [diff] [blame] | 265 | ath_restart_work(sc); |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 266 | ath_txq_schedule_all(sc); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 269 | sc->gtt_cnt = 0; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 270 | ieee80211_wake_queues(sc->hw); |
| 271 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 272 | ath9k_p2p_ps_timer(sc); |
| 273 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 274 | return true; |
| 275 | } |
| 276 | |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 277 | int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan) |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 278 | { |
| 279 | struct ath_hw *ah = sc->sc_ah; |
| 280 | struct ath_common *common = ath9k_hw_common(ah); |
| 281 | struct ath9k_hw_cal_data *caldata = NULL; |
| 282 | bool fastcc = true; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 283 | int r; |
| 284 | |
| 285 | __ath_cancel_work(sc); |
| 286 | |
Felix Fietkau | 4668cce | 2013-01-14 16:56:46 +0100 | [diff] [blame] | 287 | tasklet_disable(&sc->intr_tq); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 288 | spin_lock_bh(&sc->sc_pcu_lock); |
| 289 | |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 290 | if (!sc->cur_chan->offchannel) { |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 291 | fastcc = false; |
Felix Fietkau | b01459e | 2014-06-11 16:17:59 +0530 | [diff] [blame] | 292 | caldata = &sc->cur_chan->caldata; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | if (!hchan) { |
| 296 | fastcc = false; |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 297 | hchan = ah->curchan; |
| 298 | } |
| 299 | |
John W. Linville | 9ebea38 | 2013-01-28 13:54:03 -0500 | [diff] [blame] | 300 | if (!ath_prepare_reset(sc)) |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 301 | fastcc = false; |
| 302 | |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 303 | if (hchan) { |
| 304 | spin_lock_bh(&sc->chan_lock); |
| 305 | sc->cur_chandef = sc->cur_chan->chandef; |
| 306 | spin_unlock_bh(&sc->chan_lock); |
| 307 | } |
| 308 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 309 | ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n", |
Sujith Manoharan | feced20 | 2012-01-30 14:21:42 +0530 | [diff] [blame] | 310 | hchan->channel, IS_CHAN_HT40(hchan), fastcc); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 311 | |
| 312 | r = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
| 313 | if (r) { |
| 314 | ath_err(common, |
| 315 | "Unable to reset channel, reset status %d\n", r); |
Robert Shade | f50b1cd | 2013-04-02 19:52:45 -0400 | [diff] [blame] | 316 | |
| 317 | ath9k_hw_enable_interrupts(ah); |
| 318 | ath9k_queue_reset(sc, RESET_TYPE_BB_HANG); |
| 319 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 320 | goto out; |
| 321 | } |
| 322 | |
Rajkumar Manoharan | e82cb03 | 2012-10-12 14:07:25 +0530 | [diff] [blame] | 323 | if (ath9k_hw_mci_is_enabled(sc->sc_ah) && |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 324 | sc->cur_chan->offchannel) |
Rajkumar Manoharan | e82cb03 | 2012-10-12 14:07:25 +0530 | [diff] [blame] | 325 | ath9k_mci_set_txpower(sc, true, false); |
| 326 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 327 | if (!ath_complete_reset(sc, true)) |
| 328 | r = -EIO; |
| 329 | |
| 330 | out: |
| 331 | spin_unlock_bh(&sc->sc_pcu_lock); |
Felix Fietkau | 4668cce | 2013-01-14 16:56:46 +0100 | [diff] [blame] | 332 | tasklet_enable(&sc->intr_tq); |
| 333 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 334 | return r; |
| 335 | } |
| 336 | |
Ben Greear | 7e1e386 | 2011-11-03 11:33:13 -0700 | [diff] [blame] | 337 | static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta, |
| 338 | struct ieee80211_vif *vif) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 339 | { |
| 340 | struct ath_node *an; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 341 | an = (struct ath_node *)sta->drv_priv; |
| 342 | |
Sujith Manoharan | a145daf | 2012-11-28 15:08:54 +0530 | [diff] [blame] | 343 | an->sc = sc; |
Ben Greear | 7f010c9 | 2011-01-09 23:11:49 -0800 | [diff] [blame] | 344 | an->sta = sta; |
Ben Greear | 7e1e386 | 2011-11-03 11:33:13 -0700 | [diff] [blame] | 345 | an->vif = vif; |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 346 | memset(&an->key_idx, 0, sizeof(an->key_idx)); |
Sujith Manoharan | 3d4e20f | 2012-03-14 14:40:58 +0530 | [diff] [blame] | 347 | |
Sujith Manoharan | dd5ee59 | 2013-02-04 15:38:23 +0530 | [diff] [blame] | 348 | ath_tx_node_init(sc, an); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 352 | { |
| 353 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
Sujith Manoharan | dd5ee59 | 2013-02-04 15:38:23 +0530 | [diff] [blame] | 354 | ath_tx_node_cleanup(sc, an); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 355 | } |
| 356 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 357 | void ath9k_tasklet(unsigned long data) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 358 | { |
| 359 | struct ath_softc *sc = (struct ath_softc *)data; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 360 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 361 | struct ath_common *common = ath9k_hw_common(ah); |
Rajkumar Manoharan | 124b979 | 2012-07-17 17:16:42 +0530 | [diff] [blame] | 362 | enum ath_reset_type type; |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 363 | unsigned long flags; |
Sujith | 17d7904 | 2009-02-09 13:27:03 +0530 | [diff] [blame] | 364 | u32 status = sc->intrstatus; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 365 | u32 rxmask; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 366 | |
Felix Fietkau | e392700 | 2011-09-14 21:23:01 +0200 | [diff] [blame] | 367 | ath9k_ps_wakeup(sc); |
| 368 | spin_lock(&sc->sc_pcu_lock); |
| 369 | |
Sujith Manoharan | 6549a86 | 2013-12-24 10:44:24 +0530 | [diff] [blame] | 370 | if (status & ATH9K_INT_FATAL) { |
| 371 | type = RESET_TYPE_FATAL_INT; |
Rajkumar Manoharan | 124b979 | 2012-07-17 17:16:42 +0530 | [diff] [blame] | 372 | ath9k_queue_reset(sc, type); |
Sujith Manoharan | c6cc47b | 2013-09-16 10:37:00 +0530 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * Increment the ref. counter here so that |
| 376 | * interrupts are enabled in the reset routine. |
| 377 | */ |
| 378 | atomic_inc(&ah->intr_ref_cnt); |
Felix Fietkau | affad45 | 2014-02-22 14:52:49 +0100 | [diff] [blame] | 379 | ath_dbg(common, RESET, "FATAL: Skipping interrupts\n"); |
Felix Fietkau | e392700 | 2011-09-14 21:23:01 +0200 | [diff] [blame] | 380 | goto out; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 381 | } |
| 382 | |
Sujith Manoharan | 6549a86 | 2013-12-24 10:44:24 +0530 | [diff] [blame] | 383 | if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) && |
| 384 | (status & ATH9K_INT_BB_WATCHDOG)) { |
Sujith Manoharan | 0c75997 | 2013-12-24 10:44:26 +0530 | [diff] [blame] | 385 | spin_lock(&common->cc_lock); |
| 386 | ath_hw_cycle_counters_update(common); |
| 387 | ar9003_hw_bb_watchdog_dbg_info(ah); |
| 388 | spin_unlock(&common->cc_lock); |
| 389 | |
Sujith Manoharan | 6549a86 | 2013-12-24 10:44:24 +0530 | [diff] [blame] | 390 | if (ar9003_hw_bb_watchdog_check(ah)) { |
| 391 | type = RESET_TYPE_BB_WATCHDOG; |
| 392 | ath9k_queue_reset(sc, type); |
| 393 | |
| 394 | /* |
| 395 | * Increment the ref. counter here so that |
| 396 | * interrupts are enabled in the reset routine. |
| 397 | */ |
| 398 | atomic_inc(&ah->intr_ref_cnt); |
Felix Fietkau | affad45 | 2014-02-22 14:52:49 +0100 | [diff] [blame] | 399 | ath_dbg(common, RESET, |
Sujith Manoharan | 6549a86 | 2013-12-24 10:44:24 +0530 | [diff] [blame] | 400 | "BB_WATCHDOG: Skipping interrupts\n"); |
| 401 | goto out; |
| 402 | } |
| 403 | } |
| 404 | |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 405 | if (status & ATH9K_INT_GTT) { |
| 406 | sc->gtt_cnt++; |
| 407 | |
| 408 | if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) { |
| 409 | type = RESET_TYPE_TX_GTT; |
| 410 | ath9k_queue_reset(sc, type); |
| 411 | atomic_inc(&ah->intr_ref_cnt); |
Felix Fietkau | affad45 | 2014-02-22 14:52:49 +0100 | [diff] [blame] | 412 | ath_dbg(common, RESET, |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 413 | "GTT: Skipping interrupts\n"); |
| 414 | goto out; |
| 415 | } |
| 416 | } |
| 417 | |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 418 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Rajkumar Manoharan | 4105f80 | 2011-05-06 18:27:47 +0530 | [diff] [blame] | 419 | if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { |
| 420 | /* |
| 421 | * TSF sync does not look correct; remain awake to sync with |
| 422 | * the next Beacon. |
| 423 | */ |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 424 | ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n"); |
Rajkumar Manoharan | e8fe733 | 2011-08-05 18:59:41 +0530 | [diff] [blame] | 425 | sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC; |
Rajkumar Manoharan | 4105f80 | 2011-05-06 18:27:47 +0530 | [diff] [blame] | 426 | } |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 427 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Rajkumar Manoharan | 4105f80 | 2011-05-06 18:27:47 +0530 | [diff] [blame] | 428 | |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 429 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 430 | rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL | |
| 431 | ATH9K_INT_RXORN); |
| 432 | else |
| 433 | rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
| 434 | |
| 435 | if (status & rxmask) { |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 436 | /* Check for high priority Rx first */ |
| 437 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && |
| 438 | (status & ATH9K_INT_RXHP)) |
| 439 | ath_rx_tasklet(sc, 0, true); |
| 440 | |
| 441 | ath_rx_tasklet(sc, 0, false); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 442 | } |
| 443 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 444 | if (status & ATH9K_INT_TX) { |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 445 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 446 | /* |
| 447 | * For EDMA chips, TX completion is enabled for the |
| 448 | * beacon queue, so if a beacon has been transmitted |
| 449 | * successfully after a GTT interrupt, the GTT counter |
| 450 | * gets reset to zero here. |
| 451 | */ |
Sujith Manoharan | 3b745c7 | 2014-01-20 13:25:28 +0530 | [diff] [blame] | 452 | sc->gtt_cnt = 0; |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 453 | |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 454 | ath_tx_edma_tasklet(sc); |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 455 | } else { |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 456 | ath_tx_tasklet(sc); |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 457 | } |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 458 | |
| 459 | wake_up(&sc->tx_wait); |
Vasanthakumar Thiagarajan | e500324 | 2010-04-15 17:39:36 -0400 | [diff] [blame] | 460 | } |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 461 | |
Felix Fietkau | c67ce33 | 2013-12-14 18:03:38 +0100 | [diff] [blame] | 462 | if (status & ATH9K_INT_GENTIMER) |
| 463 | ath_gen_timer_isr(sc->sc_ah); |
| 464 | |
Sujith Manoharan | 56ca0db | 2012-02-22 12:40:32 +0530 | [diff] [blame] | 465 | ath9k_btcoex_handle_interrupt(sc, status); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 466 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 467 | /* re-enable hardware interrupt */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 468 | ath9k_hw_enable_interrupts(ah); |
Sujith Manoharan | c6cc47b | 2013-09-16 10:37:00 +0530 | [diff] [blame] | 469 | out: |
Senthil Balasubramanian | 52671e4 | 2010-12-23 21:06:57 +0530 | [diff] [blame] | 470 | spin_unlock(&sc->sc_pcu_lock); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 471 | ath9k_ps_restore(sc); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 472 | } |
| 473 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 474 | irqreturn_t ath_isr(int irq, void *dev) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 475 | { |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 476 | #define SCHED_INTR ( \ |
| 477 | ATH9K_INT_FATAL | \ |
Rajkumar Manoharan | a4d86d9 | 2011-05-20 17:52:10 +0530 | [diff] [blame] | 478 | ATH9K_INT_BB_WATCHDOG | \ |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 479 | ATH9K_INT_RXORN | \ |
| 480 | ATH9K_INT_RXEOL | \ |
| 481 | ATH9K_INT_RX | \ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 482 | ATH9K_INT_RXLP | \ |
| 483 | ATH9K_INT_RXHP | \ |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 484 | ATH9K_INT_TX | \ |
| 485 | ATH9K_INT_BMISS | \ |
| 486 | ATH9K_INT_CST | \ |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 487 | ATH9K_INT_GTT | \ |
Vasanthakumar Thiagarajan | ebb8e1d | 2009-09-01 17:46:32 +0530 | [diff] [blame] | 488 | ATH9K_INT_TSFOOR | \ |
Mohammed Shafi Shajakhan | 40dc539 | 2011-11-30 10:41:18 +0530 | [diff] [blame] | 489 | ATH9K_INT_GENTIMER | \ |
| 490 | ATH9K_INT_MCI) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 491 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 492 | struct ath_softc *sc = dev; |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 493 | struct ath_hw *ah = sc->sc_ah; |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 494 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 495 | enum ath9k_int status; |
Sujith Manoharan | 78c8a95 | 2013-12-28 09:47:15 +0530 | [diff] [blame] | 496 | u32 sync_cause = 0; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 497 | bool sched = false; |
| 498 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 499 | /* |
| 500 | * The hardware is not ready/present, don't |
| 501 | * touch anything. Note this can happen early |
| 502 | * on if the IRQ is shared. |
| 503 | */ |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 504 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 505 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 506 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 507 | /* shared irq, not for us */ |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 508 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 509 | if (!ath9k_hw_intrpend(ah)) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 510 | return IRQ_NONE; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 511 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 512 | if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) { |
Felix Fietkau | f41a9b3 | 2012-08-08 16:25:03 +0200 | [diff] [blame] | 513 | ath9k_hw_kill_interrupts(ah); |
Sujith Manoharan | b74713d | 2012-06-04 20:24:01 +0530 | [diff] [blame] | 514 | return IRQ_HANDLED; |
Felix Fietkau | f41a9b3 | 2012-08-08 16:25:03 +0200 | [diff] [blame] | 515 | } |
Sujith Manoharan | b74713d | 2012-06-04 20:24:01 +0530 | [diff] [blame] | 516 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 517 | /* |
| 518 | * Figure out the reason(s) for the interrupt. Note |
| 519 | * that the hal returns a pseudo-ISR that may include |
| 520 | * bits we haven't explicitly enabled so we mask the |
| 521 | * value to insure we only process bits we requested. |
| 522 | */ |
Felix Fietkau | 6a4d05d | 2013-12-19 18:01:48 +0100 | [diff] [blame] | 523 | ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */ |
| 524 | ath9k_debug_sync_cause(sc, sync_cause); |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 525 | status &= ah->imask; /* discard unasked-for bits */ |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 526 | |
| 527 | /* |
| 528 | * If there are no status bits set, then this interrupt was not |
| 529 | * for me (should have been caught above). |
| 530 | */ |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 531 | if (!status) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 532 | return IRQ_NONE; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 533 | |
| 534 | /* Cache the status */ |
| 535 | sc->intrstatus = status; |
| 536 | |
| 537 | if (status & SCHED_INTR) |
| 538 | sched = true; |
| 539 | |
| 540 | /* |
| 541 | * If a FATAL or RXORN interrupt is received, we have to reset the |
| 542 | * chip immediately. |
| 543 | */ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 544 | if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) && |
| 545 | !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA))) |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 546 | goto chip_reset; |
| 547 | |
Sujith Manoharan | a6bb860 | 2013-12-24 10:44:22 +0530 | [diff] [blame] | 548 | if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) && |
Sujith Manoharan | 0c75997 | 2013-12-24 10:44:26 +0530 | [diff] [blame] | 549 | (status & ATH9K_INT_BB_WATCHDOG)) |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 550 | goto chip_reset; |
Sujith Manoharan | e60001e | 2013-10-28 12:22:04 +0530 | [diff] [blame] | 551 | |
| 552 | #ifdef CONFIG_ATH9K_WOW |
Rajkumar Manoharan | ca90ef4 | 2012-11-20 18:29:59 +0530 | [diff] [blame] | 553 | if (status & ATH9K_INT_BMISS) { |
| 554 | if (atomic_read(&sc->wow_sleep_proc_intr) == 0) { |
Rajkumar Manoharan | ca90ef4 | 2012-11-20 18:29:59 +0530 | [diff] [blame] | 555 | atomic_inc(&sc->wow_got_bmiss_intr); |
| 556 | atomic_dec(&sc->wow_sleep_proc_intr); |
| 557 | } |
| 558 | } |
| 559 | #endif |
Sujith Manoharan | e60001e | 2013-10-28 12:22:04 +0530 | [diff] [blame] | 560 | |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 561 | if (status & ATH9K_INT_SWBA) |
| 562 | tasklet_schedule(&sc->bcon_tasklet); |
| 563 | |
| 564 | if (status & ATH9K_INT_TXURN) |
| 565 | ath9k_hw_updatetxtriglevel(ah, true); |
| 566 | |
Rajkumar Manoharan | 0682c9b | 2011-08-13 10:28:09 +0530 | [diff] [blame] | 567 | if (status & ATH9K_INT_RXEOL) { |
| 568 | ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 569 | ath9k_hw_set_interrupts(ah); |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 570 | } |
| 571 | |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 572 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 573 | if (status & ATH9K_INT_TIM_TIMER) { |
Luis R. Rodriguez | ff9f0b6 | 2010-12-07 15:13:22 -0800 | [diff] [blame] | 574 | if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle)) |
| 575 | goto chip_reset; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 576 | /* Clear RxAbort bit so that we can |
| 577 | * receive frames */ |
Luis R. Rodriguez | 9ecdef4 | 2009-09-09 21:10:09 -0700 | [diff] [blame] | 578 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 579 | spin_lock(&sc->sc_pm_lock); |
Vasanthakumar Thiagarajan | 153e080 | 2009-05-15 02:47:16 -0400 | [diff] [blame] | 580 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 581 | sc->ps_flags |= PS_WAIT_FOR_BEACON; |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 582 | spin_unlock(&sc->sc_pm_lock); |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 583 | } |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 584 | |
| 585 | chip_reset: |
| 586 | |
Sujith | 817e11d | 2008-12-07 21:42:44 +0530 | [diff] [blame] | 587 | ath_debug_stat_interrupt(sc, status); |
| 588 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 589 | if (sched) { |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 590 | /* turn off every interrupt */ |
| 591 | ath9k_hw_disable_interrupts(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 592 | tasklet_schedule(&sc->intr_tq); |
| 593 | } |
| 594 | |
| 595 | return IRQ_HANDLED; |
Sujith | 063d8be | 2009-03-30 15:28:49 +0530 | [diff] [blame] | 596 | |
| 597 | #undef SCHED_INTR |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 598 | } |
| 599 | |
Sujith Manoharan | ef6b19e | 2013-10-24 12:04:39 +0530 | [diff] [blame] | 600 | int ath_reset(struct ath_softc *sc) |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 601 | { |
Felix Fietkau | ec30326 | 2013-10-05 14:09:30 +0200 | [diff] [blame] | 602 | int r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 603 | |
Felix Fietkau | 783cd01 | 2011-01-21 18:52:38 +0100 | [diff] [blame] | 604 | ath9k_ps_wakeup(sc); |
Felix Fietkau | 1381559 | 2013-01-20 18:51:53 +0100 | [diff] [blame] | 605 | r = ath_reset_internal(sc, NULL); |
Felix Fietkau | 783cd01 | 2011-01-21 18:52:38 +0100 | [diff] [blame] | 606 | ath9k_ps_restore(sc); |
Sujith | 2ab81d4 | 2009-12-14 16:34:56 +0530 | [diff] [blame] | 607 | |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 608 | return r; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 609 | } |
| 610 | |
Rajkumar Manoharan | 124b979 | 2012-07-17 17:16:42 +0530 | [diff] [blame] | 611 | void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type) |
| 612 | { |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 613 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Rajkumar Manoharan | 124b979 | 2012-07-17 17:16:42 +0530 | [diff] [blame] | 614 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 615 | RESET_STAT_INC(sc, type); |
| 616 | #endif |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 617 | set_bit(ATH_OP_HW_RESET, &common->op_flags); |
Rajkumar Manoharan | 124b979 | 2012-07-17 17:16:42 +0530 | [diff] [blame] | 618 | ieee80211_queue_work(sc->hw, &sc->hw_reset_work); |
| 619 | } |
| 620 | |
Felix Fietkau | 236de51 | 2011-09-03 01:40:25 +0200 | [diff] [blame] | 621 | void ath_reset_work(struct work_struct *work) |
| 622 | { |
| 623 | struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work); |
| 624 | |
Felix Fietkau | 1381559 | 2013-01-20 18:51:53 +0100 | [diff] [blame] | 625 | ath_reset(sc); |
Felix Fietkau | 236de51 | 2011-09-03 01:40:25 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 628 | /**********************/ |
| 629 | /* mac80211 callbacks */ |
| 630 | /**********************/ |
| 631 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 632 | static int ath9k_start(struct ieee80211_hw *hw) |
| 633 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 634 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 635 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 636 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 637 | struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan; |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 638 | struct ath_chanctx *ctx = sc->cur_chan; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 639 | struct ath9k_channel *init_channel; |
Vasanthakumar Thiagarajan | 82880a7 | 2009-06-13 14:50:24 +0530 | [diff] [blame] | 640 | int r; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 641 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 642 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 643 | "Starting driver with initial channel: %d MHz\n", |
| 644 | curchan->center_freq); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 645 | |
Felix Fietkau | f62d816 | 2011-03-25 17:43:41 +0100 | [diff] [blame] | 646 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 647 | mutex_lock(&sc->mutex); |
| 648 | |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 649 | init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef); |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 650 | sc->cur_chandef = hw->conf.chandef; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 651 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 652 | /* Reset SERDES registers */ |
Stanislaw Gruszka | 84c87dc | 2011-08-05 13:10:32 +0200 | [diff] [blame] | 653 | ath9k_hw_configpcipowersave(ah, false); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | * The basic interface to setting the hardware in a good |
| 657 | * state is ``reset''. On return the hardware is known to |
| 658 | * be powered up and with interrupts disabled. This must |
| 659 | * be followed by initialization of the appropriate bits |
| 660 | * and then setup of the interrupt mask. |
| 661 | */ |
Luis R. Rodriguez | 4bdd1e9 | 2010-10-26 15:27:24 -0700 | [diff] [blame] | 662 | spin_lock_bh(&sc->sc_pcu_lock); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 663 | |
| 664 | atomic_set(&ah->intr_ref_cnt, -1); |
| 665 | |
Felix Fietkau | 20bd2a0 | 2010-07-31 00:12:00 +0200 | [diff] [blame] | 666 | r = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
Luis R. Rodriguez | ae8d285 | 2008-12-23 15:58:40 -0800 | [diff] [blame] | 667 | if (r) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 668 | ath_err(common, |
| 669 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 670 | r, curchan->center_freq); |
Felix Fietkau | ceb26a6 | 2012-10-03 21:07:51 +0200 | [diff] [blame] | 671 | ah->reset_power_on = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 672 | } |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 673 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 674 | /* Setup our intr mask. */ |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 675 | ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL | |
| 676 | ATH9K_INT_RXORN | ATH9K_INT_FATAL | |
| 677 | ATH9K_INT_GLOBAL; |
| 678 | |
| 679 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
Luis R. Rodriguez | 08578b8 | 2010-05-13 13:33:44 -0400 | [diff] [blame] | 680 | ah->imask |= ATH9K_INT_RXHP | |
Sujith Manoharan | a6bb860 | 2013-12-24 10:44:22 +0530 | [diff] [blame] | 681 | ATH9K_INT_RXLP; |
Felix Fietkau | b5c80475 | 2010-04-15 17:38:48 -0400 | [diff] [blame] | 682 | else |
| 683 | ah->imask |= ATH9K_INT_RX; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 684 | |
Sujith Manoharan | a6bb860 | 2013-12-24 10:44:22 +0530 | [diff] [blame] | 685 | if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) |
| 686 | ah->imask |= ATH9K_INT_BB_WATCHDOG; |
| 687 | |
Sujith Manoharan | 071aa9a | 2014-01-13 13:55:11 +0530 | [diff] [blame] | 688 | /* |
| 689 | * Enable GTT interrupts only for AR9003/AR9004 chips |
| 690 | * for now. |
| 691 | */ |
| 692 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 693 | ah->imask |= ATH9K_INT_GTT; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 694 | |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 695 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 696 | ah->imask |= ATH9K_INT_CST; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 697 | |
Sujith Manoharan | e270e77 | 2012-06-04 16:27:19 +0530 | [diff] [blame] | 698 | ath_mci_enable(sc); |
Mohammed Shafi Shajakhan | 40dc539 | 2011-11-30 10:41:18 +0530 | [diff] [blame] | 699 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 700 | clear_bit(ATH_OP_INVALID, &common->op_flags); |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 701 | sc->sc_ah->is_monitoring = false; |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 702 | |
Felix Fietkau | ceb26a6 | 2012-10-03 21:07:51 +0200 | [diff] [blame] | 703 | if (!ath_complete_reset(sc, false)) |
| 704 | ah->reset_power_on = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 705 | |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 706 | if (ah->led_pin >= 0) { |
| 707 | ath9k_hw_cfg_output(ah, ah->led_pin, |
| 708 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 709 | ath9k_hw_set_gpio(ah, ah->led_pin, 0); |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * Reset key cache to sane defaults (all entries cleared) instead of |
| 714 | * semi-random values after suspend/resume. |
| 715 | */ |
| 716 | ath9k_cmn_init_crypto(sc->sc_ah); |
| 717 | |
Felix Fietkau | a35051c | 2013-12-14 18:03:45 +0100 | [diff] [blame] | 718 | ath9k_hw_reset_tsf(ah); |
| 719 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 720 | spin_unlock_bh(&sc->sc_pcu_lock); |
Senthil Balasubramanian | 164ace3 | 2009-07-14 20:17:09 -0400 | [diff] [blame] | 721 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 722 | mutex_unlock(&sc->mutex); |
| 723 | |
Felix Fietkau | f62d816 | 2011-03-25 17:43:41 +0100 | [diff] [blame] | 724 | ath9k_ps_restore(sc); |
| 725 | |
Felix Fietkau | ceb26a6 | 2012-10-03 21:07:51 +0200 | [diff] [blame] | 726 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 729 | static void ath9k_tx(struct ieee80211_hw *hw, |
| 730 | struct ieee80211_tx_control *control, |
| 731 | struct sk_buff *skb) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 732 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 733 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 734 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 735 | struct ath_tx_control txctl; |
Benoit Papillault | 1bc1488 | 2009-11-24 15:49:18 +0100 | [diff] [blame] | 736 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 737 | unsigned long flags; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 738 | |
Gabor Juhos | 9614832 | 2009-07-24 17:27:21 +0200 | [diff] [blame] | 739 | if (sc->ps_enabled) { |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 740 | /* |
| 741 | * mac80211 does not set PM field for normal data frames, so we |
| 742 | * need to update that based on the current PS mode. |
| 743 | */ |
| 744 | if (ieee80211_is_data(hdr->frame_control) && |
| 745 | !ieee80211_is_nullfunc(hdr->frame_control) && |
| 746 | !ieee80211_has_pm(hdr->frame_control)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 747 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 748 | "Add PM=1 for a TX frame while in PS mode\n"); |
Jouni Malinen | dc8c458 | 2009-05-19 17:01:42 +0300 | [diff] [blame] | 749 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 750 | } |
| 751 | } |
| 752 | |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 753 | if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) { |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 754 | /* |
| 755 | * We are using PS-Poll and mac80211 can request TX while in |
| 756 | * power save mode. Need to wake up hardware for the TX to be |
| 757 | * completed and if needed, also for RX of buffered frames. |
| 758 | */ |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 759 | ath9k_ps_wakeup(sc); |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 760 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Vasanthakumar Thiagarajan | fdf7662 | 2010-05-17 18:57:55 -0700 | [diff] [blame] | 761 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 762 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 763 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 764 | ath_dbg(common, PS, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 765 | "Sending PS-Poll to pick a buffered frame\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 766 | sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA; |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 767 | } else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 768 | ath_dbg(common, PS, "Wake up to complete TX\n"); |
Sujith | 1b04b93 | 2010-01-08 10:36:05 +0530 | [diff] [blame] | 769 | sc->ps_flags |= PS_WAIT_FOR_TX_ACK; |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 770 | } |
| 771 | /* |
| 772 | * The actual restore operation will happen only after |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 773 | * the ps_flags bit is cleared. We are just dropping |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 774 | * the ps_usecount here. |
| 775 | */ |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 776 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Jouni Malinen | 9a23f9c | 2009-05-19 17:01:38 +0300 | [diff] [blame] | 777 | ath9k_ps_restore(sc); |
| 778 | } |
| 779 | |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 780 | /* |
| 781 | * Cannot tx while the hardware is in full sleep, it first needs a full |
| 782 | * chip reset to recover from that |
| 783 | */ |
| 784 | if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) { |
| 785 | ath_err(common, "TX while HW is in FULL_SLEEP mode\n"); |
| 786 | goto exit; |
| 787 | } |
| 788 | |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 789 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 790 | txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)]; |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 791 | txctl.sta = control->sta; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 792 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 793 | ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 794 | |
Jouni Malinen | c52f33d | 2009-03-03 19:23:29 +0200 | [diff] [blame] | 795 | if (ath_tx_start(hw, skb, &txctl) != 0) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 796 | ath_dbg(common, XMIT, "TX failed\n"); |
Ben Greear | a5a0bca | 2012-04-03 09:16:55 -0700 | [diff] [blame] | 797 | TX_STAT_INC(txctl.txq->axq_qnum, txfailed); |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 798 | goto exit; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 801 | return; |
Sujith | 528f0c6 | 2008-10-29 10:14:26 +0530 | [diff] [blame] | 802 | exit: |
Felix Fietkau | 249ee72 | 2012-10-03 21:07:52 +0200 | [diff] [blame] | 803 | ieee80211_free_txskb(hw, skb); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static void ath9k_stop(struct ieee80211_hw *hw) |
| 807 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 808 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | af03abe | 2009-09-09 02:33:11 -0700 | [diff] [blame] | 809 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 810 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 811 | bool prev_idle; |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 812 | |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 813 | cancel_work_sync(&sc->chanctx_work); |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 814 | mutex_lock(&sc->mutex); |
| 815 | |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 816 | ath_cancel_work(sc); |
Luis R. Rodriguez | c94dbff | 2009-07-27 11:53:04 -0700 | [diff] [blame] | 817 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 818 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 819 | ath_dbg(common, ANY, "Device not present\n"); |
Sujith | 4c48381 | 2009-08-18 10:51:52 +0530 | [diff] [blame] | 820 | mutex_unlock(&sc->mutex); |
Sujith | 9c84b79 | 2008-10-29 10:17:13 +0530 | [diff] [blame] | 821 | return; |
| 822 | } |
| 823 | |
Sujith | 3867cf6 | 2009-12-23 20:03:27 -0500 | [diff] [blame] | 824 | /* Ensure HW is awake when we try to shut it down. */ |
| 825 | ath9k_ps_wakeup(sc); |
| 826 | |
Luis R. Rodriguez | 6a6733f | 2010-10-26 15:27:25 -0700 | [diff] [blame] | 827 | spin_lock_bh(&sc->sc_pcu_lock); |
| 828 | |
Stanislaw Gruszka | 203043f | 2011-01-25 14:08:40 +0100 | [diff] [blame] | 829 | /* prevent tasklets to enable interrupts once we disable them */ |
| 830 | ah->imask &= ~ATH9K_INT_GLOBAL; |
| 831 | |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 832 | /* make sure h/w will not generate any interrupt |
| 833 | * before setting the invalid flag. */ |
Felix Fietkau | 4df3071 | 2010-11-08 20:54:47 +0100 | [diff] [blame] | 834 | ath9k_hw_disable_interrupts(ah); |
Sujith | ff37e33 | 2008-11-24 12:07:55 +0530 | [diff] [blame] | 835 | |
Luis R. Rodriguez | 6a6733f | 2010-10-26 15:27:25 -0700 | [diff] [blame] | 836 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 837 | |
Stanislaw Gruszka | 203043f | 2011-01-25 14:08:40 +0100 | [diff] [blame] | 838 | /* we can now sync irq and kill any running tasklets, since we already |
| 839 | * disabled interrupts and not holding a spin lock */ |
| 840 | synchronize_irq(sc->irq); |
| 841 | tasklet_kill(&sc->intr_tq); |
| 842 | tasklet_kill(&sc->bcon_tasklet); |
| 843 | |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 844 | prev_idle = sc->ps_idle; |
| 845 | sc->ps_idle = true; |
| 846 | |
| 847 | spin_lock_bh(&sc->sc_pcu_lock); |
| 848 | |
| 849 | if (ah->led_pin >= 0) { |
| 850 | ath9k_hw_set_gpio(ah, ah->led_pin, 1); |
| 851 | ath9k_hw_cfg_gpio_input(ah, ah->led_pin); |
| 852 | } |
| 853 | |
John W. Linville | 9ebea38 | 2013-01-28 13:54:03 -0500 | [diff] [blame] | 854 | ath_prepare_reset(sc); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 855 | |
| 856 | if (sc->rx.frag) { |
| 857 | dev_kfree_skb_any(sc->rx.frag); |
| 858 | sc->rx.frag = NULL; |
| 859 | } |
| 860 | |
| 861 | if (!ah->curchan) |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 862 | ah->curchan = ath9k_cmn_get_channel(hw, ah, |
| 863 | &sc->cur_chan->chandef); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 864 | |
| 865 | ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
| 866 | ath9k_hw_phy_disable(ah); |
| 867 | |
| 868 | ath9k_hw_configpcipowersave(ah, true); |
| 869 | |
| 870 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 871 | |
Sujith | 3867cf6 | 2009-12-23 20:03:27 -0500 | [diff] [blame] | 872 | ath9k_ps_restore(sc); |
| 873 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 874 | set_bit(ATH_OP_INVALID, &common->op_flags); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 875 | sc->ps_idle = prev_idle; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 876 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 877 | mutex_unlock(&sc->mutex); |
| 878 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 879 | ath_dbg(common, CONFIG, "Driver halt\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Felix Fietkau | c648ecb | 2013-10-11 23:31:00 +0200 | [diff] [blame] | 882 | static bool ath9k_uses_beacons(int type) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 883 | { |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 884 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 885 | case NL80211_IFTYPE_AP: |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 886 | case NL80211_IFTYPE_ADHOC: |
Pat Erley | 9cb5412 | 2009-03-20 22:59:59 -0400 | [diff] [blame] | 887 | case NL80211_IFTYPE_MESH_POINT: |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 888 | return true; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 889 | default: |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 890 | return false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 891 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 894 | static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 895 | { |
| 896 | struct ath9k_vif_iter_data *iter_data = data; |
| 897 | int i; |
| 898 | |
Felix Fietkau | ab11bb2 | 2013-04-16 12:51:57 +0200 | [diff] [blame] | 899 | if (iter_data->has_hw_macaddr) { |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 900 | for (i = 0; i < ETH_ALEN; i++) |
| 901 | iter_data->mask[i] &= |
| 902 | ~(iter_data->hw_macaddr[i] ^ mac[i]); |
Felix Fietkau | ab11bb2 | 2013-04-16 12:51:57 +0200 | [diff] [blame] | 903 | } else { |
| 904 | memcpy(iter_data->hw_macaddr, mac, ETH_ALEN); |
| 905 | iter_data->has_hw_macaddr = true; |
| 906 | } |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 907 | |
| 908 | switch (vif->type) { |
| 909 | case NL80211_IFTYPE_AP: |
| 910 | iter_data->naps++; |
| 911 | break; |
| 912 | case NL80211_IFTYPE_STATION: |
| 913 | iter_data->nstations++; |
| 914 | break; |
| 915 | case NL80211_IFTYPE_ADHOC: |
| 916 | iter_data->nadhocs++; |
| 917 | break; |
| 918 | case NL80211_IFTYPE_MESH_POINT: |
| 919 | iter_data->nmeshes++; |
| 920 | break; |
| 921 | case NL80211_IFTYPE_WDS: |
| 922 | iter_data->nwds++; |
| 923 | break; |
| 924 | default: |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 925 | break; |
| 926 | } |
| 927 | } |
| 928 | |
Sujith Manoharan | 6dcc344 | 2012-07-17 17:16:36 +0530 | [diff] [blame] | 929 | static void ath9k_sta_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 930 | { |
| 931 | struct ath_softc *sc = data; |
| 932 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 933 | |
| 934 | if (vif->type != NL80211_IFTYPE_STATION) |
| 935 | return; |
| 936 | |
| 937 | if (avp->primary_sta_vif) |
| 938 | ath9k_set_assoc_state(sc, vif); |
| 939 | } |
| 940 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 941 | /* Called with sc->mutex held. */ |
| 942 | void ath9k_calculate_iter_data(struct ieee80211_hw *hw, |
| 943 | struct ieee80211_vif *vif, |
| 944 | struct ath9k_vif_iter_data *iter_data) |
| 945 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 946 | struct ath_softc *sc = hw->priv; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 947 | struct ath_hw *ah = sc->sc_ah; |
| 948 | struct ath_common *common = ath9k_hw_common(ah); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 949 | |
| 950 | /* |
Mathy Vanhoef | 657eb17 | 2013-11-28 12:21:45 +0100 | [diff] [blame] | 951 | * Pick the MAC address of the first interface as the new hardware |
| 952 | * MAC address. The hardware will use it together with the BSSID mask |
| 953 | * when matching addresses. |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 954 | */ |
| 955 | memset(iter_data, 0, sizeof(*iter_data)); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 956 | memset(&iter_data->mask, 0xff, ETH_ALEN); |
| 957 | |
| 958 | if (vif) |
| 959 | ath9k_vif_iter(iter_data, vif->addr, vif); |
| 960 | |
| 961 | /* Get list of all active MAC addresses */ |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 962 | ieee80211_iterate_active_interfaces_atomic( |
| 963 | sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 964 | ath9k_vif_iter, iter_data); |
Felix Fietkau | ab11bb2 | 2013-04-16 12:51:57 +0200 | [diff] [blame] | 965 | |
| 966 | memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /* Called with sc->mutex held. */ |
| 970 | static void ath9k_calculate_summary_state(struct ieee80211_hw *hw, |
| 971 | struct ieee80211_vif *vif) |
| 972 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 973 | struct ath_softc *sc = hw->priv; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 974 | struct ath_hw *ah = sc->sc_ah; |
| 975 | struct ath_common *common = ath9k_hw_common(ah); |
| 976 | struct ath9k_vif_iter_data iter_data; |
Sujith Manoharan | 6dcc344 | 2012-07-17 17:16:36 +0530 | [diff] [blame] | 977 | enum nl80211_iftype old_opmode = ah->opmode; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 978 | |
| 979 | ath9k_calculate_iter_data(hw, vif, &iter_data); |
| 980 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 981 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); |
| 982 | ath_hw_setbssidmask(common); |
| 983 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 984 | if (iter_data.naps > 0) { |
Sujith Manoharan | 60ca9f8 | 2012-07-17 17:15:37 +0530 | [diff] [blame] | 985 | ath9k_hw_set_tsfadjust(ah, true); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 986 | ah->opmode = NL80211_IFTYPE_AP; |
| 987 | } else { |
Sujith Manoharan | 60ca9f8 | 2012-07-17 17:15:37 +0530 | [diff] [blame] | 988 | ath9k_hw_set_tsfadjust(ah, false); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 989 | |
Javier Cardona | fd5999c | 2011-05-03 16:57:19 -0700 | [diff] [blame] | 990 | if (iter_data.nmeshes) |
| 991 | ah->opmode = NL80211_IFTYPE_MESH_POINT; |
| 992 | else if (iter_data.nwds) |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 993 | ah->opmode = NL80211_IFTYPE_AP; |
| 994 | else if (iter_data.nadhocs) |
| 995 | ah->opmode = NL80211_IFTYPE_ADHOC; |
| 996 | else |
| 997 | ah->opmode = NL80211_IFTYPE_STATION; |
| 998 | } |
| 999 | |
Sujith Manoharan | df35d29 | 2012-07-17 17:15:43 +0530 | [diff] [blame] | 1000 | ath9k_hw_setopmode(ah); |
| 1001 | |
Felix Fietkau | 198823f | 2012-06-15 15:25:25 +0200 | [diff] [blame] | 1002 | if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1003 | ah->imask |= ATH9K_INT_TSFOOR; |
Felix Fietkau | 198823f | 2012-06-15 15:25:25 +0200 | [diff] [blame] | 1004 | else |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1005 | ah->imask &= ~ATH9K_INT_TSFOOR; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1006 | |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 1007 | ath9k_hw_set_interrupts(ah); |
Sujith Manoharan | 6dcc344 | 2012-07-17 17:16:36 +0530 | [diff] [blame] | 1008 | |
| 1009 | /* |
| 1010 | * If we are changing the opmode to STATION, |
| 1011 | * a beacon sync needs to be done. |
| 1012 | */ |
| 1013 | if (ah->opmode == NL80211_IFTYPE_STATION && |
| 1014 | old_opmode == NL80211_IFTYPE_AP && |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1015 | test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) { |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1016 | ieee80211_iterate_active_interfaces_atomic( |
| 1017 | sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1018 | ath9k_sta_vif_iter, sc); |
Sujith Manoharan | 6dcc344 | 2012-07-17 17:16:36 +0530 | [diff] [blame] | 1019 | } |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1022 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
| 1023 | struct ieee80211_vif *vif) |
| 1024 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1025 | struct ath_softc *sc = hw->priv; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1026 | struct ath_hw *ah = sc->sc_ah; |
| 1027 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | f89d1bc | 2013-08-06 14:18:13 +0200 | [diff] [blame] | 1028 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1029 | struct ath_node *an = &avp->mcast_node; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1030 | |
| 1031 | mutex_lock(&sc->mutex); |
| 1032 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1033 | if (config_enabled(CONFIG_ATH9K_TX99)) { |
| 1034 | if (sc->nvifs >= 1) { |
| 1035 | mutex_unlock(&sc->mutex); |
| 1036 | return -EOPNOTSUPP; |
| 1037 | } |
| 1038 | sc->tx99_vif = vif; |
| 1039 | } |
| 1040 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1041 | ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1042 | sc->nvifs++; |
| 1043 | |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1044 | ath9k_ps_wakeup(sc); |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1045 | ath9k_calculate_summary_state(hw, vif); |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1046 | ath9k_ps_restore(sc); |
| 1047 | |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1048 | if (ath9k_uses_beacons(vif->type)) |
| 1049 | ath9k_beacon_assign_slot(sc, vif); |
| 1050 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1051 | avp->vif = vif; |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 1052 | if (!ath9k_use_chanctx) |
| 1053 | avp->chanctx = sc->cur_chan; |
Felix Fietkau | 0453531 | 2014-06-11 16:17:51 +0530 | [diff] [blame] | 1054 | |
Felix Fietkau | f89d1bc | 2013-08-06 14:18:13 +0200 | [diff] [blame] | 1055 | an->sc = sc; |
| 1056 | an->sta = NULL; |
| 1057 | an->vif = vif; |
| 1058 | an->no_ps_filter = true; |
| 1059 | ath_tx_node_init(sc, an); |
| 1060 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1061 | mutex_unlock(&sc->mutex); |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1062 | return 0; |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1065 | static int ath9k_change_interface(struct ieee80211_hw *hw, |
| 1066 | struct ieee80211_vif *vif, |
| 1067 | enum nl80211_iftype new_type, |
| 1068 | bool p2p) |
| 1069 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1070 | struct ath_softc *sc = hw->priv; |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1071 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | c083ce9 | 2014-06-11 16:17:54 +0530 | [diff] [blame] | 1072 | struct ath_vif *avp = (void *)vif->drv_priv; |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1073 | |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1074 | mutex_lock(&sc->mutex); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1075 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1076 | if (config_enabled(CONFIG_ATH9K_TX99)) { |
| 1077 | mutex_unlock(&sc->mutex); |
| 1078 | return -EOPNOTSUPP; |
| 1079 | } |
| 1080 | |
| 1081 | ath_dbg(common, CONFIG, "Change Interface\n"); |
| 1082 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1083 | if (ath9k_uses_beacons(vif->type)) |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1084 | ath9k_beacon_remove_slot(sc, vif); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1085 | |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1086 | vif->type = new_type; |
| 1087 | vif->p2p = p2p; |
| 1088 | |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1089 | ath9k_ps_wakeup(sc); |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1090 | ath9k_calculate_summary_state(hw, vif); |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1091 | ath9k_ps_restore(sc); |
| 1092 | |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1093 | if (ath9k_uses_beacons(vif->type)) |
| 1094 | ath9k_beacon_assign_slot(sc, vif); |
Felix Fietkau | c083ce9 | 2014-06-11 16:17:54 +0530 | [diff] [blame] | 1095 | ath_chanctx_check_active(sc, avp->chanctx); |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1096 | |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1097 | mutex_unlock(&sc->mutex); |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1098 | return 0; |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 1099 | } |
| 1100 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1101 | static void |
| 1102 | ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp) |
| 1103 | { |
| 1104 | struct ath_hw *ah = sc->sc_ah; |
| 1105 | s32 tsf, target_tsf; |
| 1106 | |
| 1107 | if (!avp || !avp->noa.has_next_tsf) |
| 1108 | return; |
| 1109 | |
| 1110 | ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer); |
| 1111 | |
| 1112 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1113 | |
| 1114 | target_tsf = avp->noa.next_tsf; |
| 1115 | if (!avp->noa.absent) |
| 1116 | target_tsf -= ATH_P2P_PS_STOP_TIME; |
| 1117 | |
| 1118 | if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME) |
| 1119 | target_tsf = tsf + ATH_P2P_PS_STOP_TIME; |
| 1120 | |
| 1121 | ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000); |
| 1122 | } |
| 1123 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1124 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1125 | struct ieee80211_vif *vif) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1126 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1127 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1128 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | f89d1bc | 2013-08-06 14:18:13 +0200 | [diff] [blame] | 1129 | struct ath_vif *avp = (void *)vif->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1130 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1131 | ath_dbg(common, CONFIG, "Detach Interface\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1132 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1133 | mutex_lock(&sc->mutex); |
| 1134 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1135 | spin_lock_bh(&sc->sc_pcu_lock); |
| 1136 | if (avp == sc->p2p_ps_vif) { |
| 1137 | sc->p2p_ps_vif = NULL; |
| 1138 | ath9k_update_p2p_ps_timer(sc, NULL); |
| 1139 | } |
| 1140 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 1141 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1142 | sc->nvifs--; |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1143 | sc->tx99_vif = NULL; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1144 | |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1145 | if (ath9k_uses_beacons(vif->type)) |
Sujith Manoharan | 130ef6e | 2012-07-17 17:15:30 +0530 | [diff] [blame] | 1146 | ath9k_beacon_remove_slot(sc, vif); |
Jouni Malinen | 2c3db3d | 2009-03-03 19:23:26 +0200 | [diff] [blame] | 1147 | |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1148 | ath9k_ps_wakeup(sc); |
Ben Greear | 4801416 | 2011-01-15 19:13:48 +0000 | [diff] [blame] | 1149 | ath9k_calculate_summary_state(hw, NULL); |
Mohammed Shafi Shajakhan | 327967c | 2012-09-04 19:33:36 +0530 | [diff] [blame] | 1150 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1151 | |
Felix Fietkau | f89d1bc | 2013-08-06 14:18:13 +0200 | [diff] [blame] | 1152 | ath_tx_node_cleanup(sc, &avp->mcast_node); |
| 1153 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1154 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
Senthil Balasubramanian | fbab739 | 2010-10-05 20:36:40 +0530 | [diff] [blame] | 1157 | static void ath9k_enable_ps(struct ath_softc *sc) |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1158 | { |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1159 | struct ath_hw *ah = sc->sc_ah; |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 1160 | struct ath_common *common = ath9k_hw_common(ah); |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1161 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1162 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 1163 | return; |
| 1164 | |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1165 | sc->ps_enabled = true; |
Pavel Roskin | 3069168 | 2010-03-31 18:05:31 -0400 | [diff] [blame] | 1166 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1167 | if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) { |
| 1168 | ah->imask |= ATH9K_INT_TIM_TIMER; |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 1169 | ath9k_hw_set_interrupts(ah); |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1170 | } |
Vasanthakumar Thiagarajan | fdf7662 | 2010-05-17 18:57:55 -0700 | [diff] [blame] | 1171 | ath9k_hw_setrxabort(ah, 1); |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1172 | } |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 1173 | ath_dbg(common, PS, "PowerSave enabled\n"); |
Senthil Balasubramanian | 3f7c5c1 | 2010-02-03 22:51:13 +0530 | [diff] [blame] | 1174 | } |
| 1175 | |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1176 | static void ath9k_disable_ps(struct ath_softc *sc) |
| 1177 | { |
| 1178 | struct ath_hw *ah = sc->sc_ah; |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 1179 | struct ath_common *common = ath9k_hw_common(ah); |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1180 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1181 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 1182 | return; |
| 1183 | |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1184 | sc->ps_enabled = false; |
| 1185 | ath9k_hw_setpower(ah, ATH9K_PM_AWAKE); |
| 1186 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1187 | ath9k_hw_setrxabort(ah, 0); |
| 1188 | sc->ps_flags &= ~(PS_WAIT_FOR_BEACON | |
| 1189 | PS_WAIT_FOR_CAB | |
| 1190 | PS_WAIT_FOR_PSPOLL_DATA | |
| 1191 | PS_WAIT_FOR_TX_ACK); |
| 1192 | if (ah->imask & ATH9K_INT_TIM_TIMER) { |
| 1193 | ah->imask &= ~ATH9K_INT_TIM_TIMER; |
Felix Fietkau | 72d874c | 2011-10-08 20:06:19 +0200 | [diff] [blame] | 1194 | ath9k_hw_set_interrupts(ah); |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1195 | } |
| 1196 | } |
Sujith Manoharan | ad12886 | 2012-04-24 10:23:20 +0530 | [diff] [blame] | 1197 | ath_dbg(common, PS, "PowerSave disabled\n"); |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1198 | } |
| 1199 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1200 | void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw) |
| 1201 | { |
| 1202 | struct ath_softc *sc = hw->priv; |
| 1203 | struct ath_hw *ah = sc->sc_ah; |
| 1204 | struct ath_common *common = ath9k_hw_common(ah); |
| 1205 | u32 rxfilter; |
| 1206 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1207 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 1208 | return; |
| 1209 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1210 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { |
| 1211 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); |
| 1212 | return; |
| 1213 | } |
| 1214 | |
| 1215 | ath9k_ps_wakeup(sc); |
| 1216 | rxfilter = ath9k_hw_getrxfilter(ah); |
| 1217 | ath9k_hw_setrxfilter(ah, rxfilter | |
| 1218 | ATH9K_RX_FILTER_PHYRADAR | |
| 1219 | ATH9K_RX_FILTER_PHYERR); |
| 1220 | |
| 1221 | /* TODO: usually this should not be neccesary, but for some reason |
| 1222 | * (or in some mode?) the trigger must be called after the |
| 1223 | * configuration, otherwise the register will have its values reset |
| 1224 | * (on my ar9220 to value 0x01002310) |
| 1225 | */ |
| 1226 | ath9k_spectral_scan_config(hw, sc->spectral_mode); |
| 1227 | ath9k_hw_ops(ah)->spectral_scan_trigger(ah); |
| 1228 | ath9k_ps_restore(sc); |
| 1229 | } |
| 1230 | |
| 1231 | int ath9k_spectral_scan_config(struct ieee80211_hw *hw, |
| 1232 | enum spectral_mode spectral_mode) |
| 1233 | { |
| 1234 | struct ath_softc *sc = hw->priv; |
| 1235 | struct ath_hw *ah = sc->sc_ah; |
| 1236 | struct ath_common *common = ath9k_hw_common(ah); |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1237 | |
| 1238 | if (!ath9k_hw_ops(ah)->spectral_scan_trigger) { |
| 1239 | ath_err(common, "spectrum analyzer not implemented on this hardware\n"); |
| 1240 | return -1; |
| 1241 | } |
| 1242 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1243 | switch (spectral_mode) { |
| 1244 | case SPECTRAL_DISABLED: |
Simon Wunderlich | 04ccd4a | 2013-01-23 17:38:04 +0100 | [diff] [blame] | 1245 | sc->spec_config.enabled = 0; |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1246 | break; |
| 1247 | case SPECTRAL_BACKGROUND: |
| 1248 | /* send endless samples. |
| 1249 | * TODO: is this really useful for "background"? |
| 1250 | */ |
Simon Wunderlich | 04ccd4a | 2013-01-23 17:38:04 +0100 | [diff] [blame] | 1251 | sc->spec_config.endless = 1; |
| 1252 | sc->spec_config.enabled = 1; |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1253 | break; |
| 1254 | case SPECTRAL_CHANSCAN: |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1255 | case SPECTRAL_MANUAL: |
Simon Wunderlich | 04ccd4a | 2013-01-23 17:38:04 +0100 | [diff] [blame] | 1256 | sc->spec_config.endless = 0; |
| 1257 | sc->spec_config.enabled = 1; |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1258 | break; |
| 1259 | default: |
| 1260 | return -1; |
| 1261 | } |
| 1262 | |
| 1263 | ath9k_ps_wakeup(sc); |
Simon Wunderlich | 04ccd4a | 2013-01-23 17:38:04 +0100 | [diff] [blame] | 1264 | ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config); |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 1265 | ath9k_ps_restore(sc); |
| 1266 | |
| 1267 | sc->spectral_mode = spectral_mode; |
| 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1272 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1273 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1274 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1275 | struct ath_hw *ah = sc->sc_ah; |
| 1276 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1277 | struct ieee80211_conf *conf = &hw->conf; |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 1278 | struct ath_chanctx *ctx = sc->cur_chan; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1279 | |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 1280 | ath9k_ps_wakeup(sc); |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1281 | mutex_lock(&sc->mutex); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1282 | |
Felix Fietkau | daa1b6e | 2011-11-16 13:08:43 +0100 | [diff] [blame] | 1283 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 1284 | sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
Rajkumar Manoharan | b73f3e7 | 2012-07-01 19:53:53 +0530 | [diff] [blame] | 1285 | if (sc->ps_idle) { |
Felix Fietkau | daa1b6e | 2011-11-16 13:08:43 +0100 | [diff] [blame] | 1286 | ath_cancel_work(sc); |
Rajkumar Manoharan | b73f3e7 | 2012-07-01 19:53:53 +0530 | [diff] [blame] | 1287 | ath9k_stop_btcoex(sc); |
| 1288 | } else { |
| 1289 | ath9k_start_btcoex(sc); |
Felix Fietkau | 75600ab | 2012-04-12 20:36:31 +0200 | [diff] [blame] | 1290 | /* |
| 1291 | * The chip needs a reset to properly wake up from |
| 1292 | * full sleep |
| 1293 | */ |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 1294 | ath_chanctx_set_channel(sc, ctx, &ctx->chandef); |
Rajkumar Manoharan | b73f3e7 | 2012-07-01 19:53:53 +0530 | [diff] [blame] | 1295 | } |
Felix Fietkau | daa1b6e | 2011-11-16 13:08:43 +0100 | [diff] [blame] | 1296 | } |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1297 | |
Luis R. Rodriguez | e7824a5 | 2009-11-24 02:53:25 -0500 | [diff] [blame] | 1298 | /* |
| 1299 | * We just prepare to enable PS. We have to wait until our AP has |
| 1300 | * ACK'd our null data frame to disable RX otherwise we'll ignore |
| 1301 | * those ACKs and end up retransmitting the same null data frames. |
| 1302 | * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode. |
| 1303 | */ |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1304 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1305 | unsigned long flags; |
| 1306 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
Senthil Balasubramanian | fbab739 | 2010-10-05 20:36:40 +0530 | [diff] [blame] | 1307 | if (conf->flags & IEEE80211_CONF_PS) |
| 1308 | ath9k_enable_ps(sc); |
Senthil Balasubramanian | 845d708 | 2010-10-05 20:36:41 +0530 | [diff] [blame] | 1309 | else |
| 1310 | ath9k_disable_ps(sc); |
Luis R. Rodriguez | 8ab2cd0 | 2010-09-16 15:12:26 -0400 | [diff] [blame] | 1311 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1312 | } |
| 1313 | |
Sujith | 199afd9 | 2010-01-08 10:36:13 +0530 | [diff] [blame] | 1314 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
| 1315 | if (conf->flags & IEEE80211_CONF_MONITOR) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1316 | ath_dbg(common, CONFIG, "Monitor mode is enabled\n"); |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 1317 | sc->sc_ah->is_monitoring = true; |
| 1318 | } else { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1319 | ath_dbg(common, CONFIG, "Monitor mode is disabled\n"); |
Rajkumar Manoharan | 5f841b4 | 2010-10-27 18:31:15 +0530 | [diff] [blame] | 1320 | sc->sc_ah->is_monitoring = false; |
Sujith | 199afd9 | 2010-01-08 10:36:13 +0530 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 1324 | if (!ath9k_use_chanctx && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) { |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 1325 | ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL); |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 1326 | ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef); |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 1327 | } |
Sujith | 86b89ee | 2008-08-07 10:54:57 +0530 | [diff] [blame] | 1328 | |
Luis R. Rodriguez | c9f6a65 | 2010-01-19 14:04:19 -0500 | [diff] [blame] | 1329 | if (changed & IEEE80211_CONF_CHANGE_POWER) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1330 | ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level); |
Felix Fietkau | bc7e1be | 2014-06-11 16:17:50 +0530 | [diff] [blame] | 1331 | sc->cur_chan->txpower = 2 * conf->power_level; |
Rajkumar Manoharan | 5048e8c | 2011-01-31 23:47:44 +0530 | [diff] [blame] | 1332 | ath9k_cmn_update_txpow(ah, sc->curtxpow, |
Felix Fietkau | bc7e1be | 2014-06-11 16:17:50 +0530 | [diff] [blame] | 1333 | sc->cur_chan->txpower, &sc->curtxpow); |
Luis R. Rodriguez | 6483917 | 2009-07-14 20:22:53 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
Sujith | aa33de0 | 2008-12-18 11:40:16 +0530 | [diff] [blame] | 1336 | mutex_unlock(&sc->mutex); |
Felix Fietkau | c0c1174 | 2011-11-16 13:08:41 +0100 | [diff] [blame] | 1337 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1338 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1339 | return 0; |
| 1340 | } |
| 1341 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1342 | #define SUPPORTED_FILTERS \ |
| 1343 | (FIF_PROMISC_IN_BSS | \ |
| 1344 | FIF_ALLMULTI | \ |
| 1345 | FIF_CONTROL | \ |
Luis R. Rodriguez | af6a3fc | 2009-08-08 21:55:16 -0400 | [diff] [blame] | 1346 | FIF_PSPOLL | \ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1347 | FIF_OTHER_BSS | \ |
| 1348 | FIF_BCN_PRBRESP_PROMISC | \ |
Jouni Malinen | 9c1d8e4 | 2010-10-13 17:29:31 +0300 | [diff] [blame] | 1349 | FIF_PROBE_REQ | \ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1350 | FIF_FCSFAIL) |
| 1351 | |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1352 | /* FIXME: sc->sc_full_reset ? */ |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1353 | static void ath9k_configure_filter(struct ieee80211_hw *hw, |
| 1354 | unsigned int changed_flags, |
| 1355 | unsigned int *total_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 1356 | u64 multicast) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1357 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1358 | struct ath_softc *sc = hw->priv; |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1359 | u32 rfilt; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1360 | |
| 1361 | changed_flags &= SUPPORTED_FILTERS; |
| 1362 | *total_flags &= SUPPORTED_FILTERS; |
| 1363 | |
Sujith | b77f483 | 2008-12-07 21:44:03 +0530 | [diff] [blame] | 1364 | sc->rx.rxfilter = *total_flags; |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 1365 | ath9k_ps_wakeup(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1366 | rfilt = ath_calcrxfilter(sc); |
| 1367 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); |
Jouni Malinen | aa68aea | 2009-05-19 17:01:41 +0300 | [diff] [blame] | 1368 | ath9k_ps_restore(sc); |
Sujith | 7dcfdcd | 2008-08-11 14:03:13 +0530 | [diff] [blame] | 1369 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1370 | ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n", |
| 1371 | rfilt); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1374 | static int ath9k_sta_add(struct ieee80211_hw *hw, |
| 1375 | struct ieee80211_vif *vif, |
| 1376 | struct ieee80211_sta *sta) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1377 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1378 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1379 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1380 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1381 | struct ieee80211_key_conf ps_key = { }; |
Felix Fietkau | 4ef69d0 | 2013-04-27 11:47:01 +0200 | [diff] [blame] | 1382 | int key; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1383 | |
Ben Greear | 7e1e386 | 2011-11-03 11:33:13 -0700 | [diff] [blame] | 1384 | ath_node_attach(sc, sta, vif); |
Felix Fietkau | f59a59f | 2011-05-10 20:52:22 +0200 | [diff] [blame] | 1385 | |
| 1386 | if (vif->type != NL80211_IFTYPE_AP && |
| 1387 | vif->type != NL80211_IFTYPE_AP_VLAN) |
| 1388 | return 0; |
| 1389 | |
Felix Fietkau | 4ef69d0 | 2013-04-27 11:47:01 +0200 | [diff] [blame] | 1390 | key = ath_key_config(common, vif, sta, &ps_key); |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1391 | if (key > 0) { |
Felix Fietkau | 4ef69d0 | 2013-04-27 11:47:01 +0200 | [diff] [blame] | 1392 | an->ps_key = key; |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1393 | an->key_idx[0] = key; |
| 1394 | } |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1399 | static void ath9k_del_ps_key(struct ath_softc *sc, |
| 1400 | struct ieee80211_vif *vif, |
| 1401 | struct ieee80211_sta *sta) |
| 1402 | { |
| 1403 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1404 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1405 | struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key }; |
| 1406 | |
| 1407 | if (!an->ps_key) |
| 1408 | return; |
| 1409 | |
| 1410 | ath_key_delete(common, &ps_key); |
Felix Fietkau | 4ef69d0 | 2013-04-27 11:47:01 +0200 | [diff] [blame] | 1411 | an->ps_key = 0; |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1412 | an->key_idx[0] = 0; |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1415 | static int ath9k_sta_remove(struct ieee80211_hw *hw, |
| 1416 | struct ieee80211_vif *vif, |
| 1417 | struct ieee80211_sta *sta) |
| 1418 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1419 | struct ath_softc *sc = hw->priv; |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1420 | |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1421 | ath9k_del_ps_key(sc, vif, sta); |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 1422 | ath_node_detach(sc, sta); |
| 1423 | |
| 1424 | return 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1427 | static void ath9k_sta_set_tx_filter(struct ath_hw *ah, |
| 1428 | struct ath_node *an, |
| 1429 | bool set) |
| 1430 | { |
| 1431 | int i; |
| 1432 | |
| 1433 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1434 | if (!an->key_idx[i]) |
| 1435 | continue; |
| 1436 | ath9k_hw_set_tx_filter(ah, an->key_idx[i], set); |
| 1437 | } |
| 1438 | } |
| 1439 | |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 1440 | static void ath9k_sta_notify(struct ieee80211_hw *hw, |
| 1441 | struct ieee80211_vif *vif, |
| 1442 | enum sta_notify_cmd cmd, |
| 1443 | struct ieee80211_sta *sta) |
| 1444 | { |
| 1445 | struct ath_softc *sc = hw->priv; |
| 1446 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1447 | |
| 1448 | switch (cmd) { |
| 1449 | case STA_NOTIFY_SLEEP: |
| 1450 | an->sleeping = true; |
Johannes Berg | 042ec45 | 2011-09-29 16:04:26 +0200 | [diff] [blame] | 1451 | ath_tx_aggr_sleep(sta, sc, an); |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1452 | ath9k_sta_set_tx_filter(sc->sc_ah, an, true); |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 1453 | break; |
| 1454 | case STA_NOTIFY_AWAKE: |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1455 | ath9k_sta_set_tx_filter(sc->sc_ah, an, false); |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 1456 | an->sleeping = false; |
| 1457 | ath_tx_aggr_wakeup(sc, an); |
| 1458 | break; |
| 1459 | } |
| 1460 | } |
| 1461 | |
Eliad Peller | 8a3a3c8 | 2011-10-02 10:15:52 +0200 | [diff] [blame] | 1462 | static int ath9k_conf_tx(struct ieee80211_hw *hw, |
| 1463 | struct ieee80211_vif *vif, u16 queue, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1464 | const struct ieee80211_tx_queue_params *params) |
| 1465 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1466 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1467 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1468 | struct ath_txq *txq; |
Sujith | ea9880f | 2008-08-07 10:53:10 +0530 | [diff] [blame] | 1469 | struct ath9k_tx_queue_info qi; |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1470 | int ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1471 | |
Sujith Manoharan | bea843c | 2012-11-21 18:13:10 +0530 | [diff] [blame] | 1472 | if (queue >= IEEE80211_NUM_ACS) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1473 | return 0; |
| 1474 | |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1475 | txq = sc->tx.txq_map[queue]; |
| 1476 | |
Felix Fietkau | 96f372c | 2011-04-07 19:07:17 +0200 | [diff] [blame] | 1477 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1478 | mutex_lock(&sc->mutex); |
| 1479 | |
Sujith | 1ffb061 | 2009-03-30 15:28:46 +0530 | [diff] [blame] | 1480 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1481 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1482 | qi.tqi_aifs = params->aifs; |
| 1483 | qi.tqi_cwmin = params->cw_min; |
| 1484 | qi.tqi_cwmax = params->cw_max; |
Felix Fietkau | 531bd07 | 2012-07-15 19:53:34 +0200 | [diff] [blame] | 1485 | qi.tqi_burstTime = params->txop * 32; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1486 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1487 | ath_dbg(common, CONFIG, |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 1488 | "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1489 | queue, txq->axq_qnum, params->aifs, params->cw_min, |
| 1490 | params->cw_max, params->txop); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1491 | |
Felix Fietkau | aa5955c | 2012-07-15 19:53:36 +0200 | [diff] [blame] | 1492 | ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime); |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 1493 | ret = ath_txq_update(sc, txq->axq_qnum, &qi); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1494 | if (ret) |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1495 | ath_err(common, "TXQ Update failed\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1496 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1497 | mutex_unlock(&sc->mutex); |
Felix Fietkau | 96f372c | 2011-04-07 19:07:17 +0200 | [diff] [blame] | 1498 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1499 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1500 | return ret; |
| 1501 | } |
| 1502 | |
| 1503 | static int ath9k_set_key(struct ieee80211_hw *hw, |
| 1504 | enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 1505 | struct ieee80211_vif *vif, |
| 1506 | struct ieee80211_sta *sta, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1507 | struct ieee80211_key_conf *key) |
| 1508 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1509 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1510 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1511 | struct ath_node *an = NULL; |
| 1512 | int ret = 0, i; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1513 | |
John W. Linville | 3e6109c | 2011-01-05 09:39:17 -0500 | [diff] [blame] | 1514 | if (ath9k_modparam_nohwcrypt) |
Jouni Malinen | b3bd89c | 2009-02-24 13:42:01 +0200 | [diff] [blame] | 1515 | return -ENOSPC; |
| 1516 | |
Chun-Yeow Yeoh | 5bd5e9a | 2011-12-07 12:45:46 -0800 | [diff] [blame] | 1517 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 1518 | vif->type == NL80211_IFTYPE_MESH_POINT) && |
Jouni Malinen | cfdc9a8 | 2011-03-23 14:52:19 +0200 | [diff] [blame] | 1519 | (key->cipher == WLAN_CIPHER_SUITE_TKIP || |
| 1520 | key->cipher == WLAN_CIPHER_SUITE_CCMP) && |
| 1521 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 1522 | /* |
| 1523 | * For now, disable hw crypto for the RSN IBSS group keys. This |
| 1524 | * could be optimized in the future to use a modified key cache |
| 1525 | * design to support per-STA RX GTK, but until that gets |
| 1526 | * implemented, use of software crypto for group addressed |
| 1527 | * frames is a acceptable to allow RSN IBSS to be used. |
| 1528 | */ |
| 1529 | return -EOPNOTSUPP; |
| 1530 | } |
| 1531 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1532 | mutex_lock(&sc->mutex); |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1533 | ath9k_ps_wakeup(sc); |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1534 | ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd); |
| 1535 | if (sta) |
| 1536 | an = (struct ath_node *)sta->drv_priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1537 | |
| 1538 | switch (cmd) { |
| 1539 | case SET_KEY: |
Felix Fietkau | 93ae2dd | 2011-04-17 23:28:10 +0200 | [diff] [blame] | 1540 | if (sta) |
| 1541 | ath9k_del_ps_key(sc, vif, sta); |
| 1542 | |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1543 | key->hw_key_idx = 0; |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1544 | ret = ath_key_config(common, vif, sta, key); |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 1545 | if (ret >= 0) { |
| 1546 | key->hw_key_idx = ret; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1547 | /* push IV and Michael MIC generation to stack */ |
| 1548 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1549 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
Senthil Balasubramanian | 1b96175 | 2008-09-01 19:45:21 +0530 | [diff] [blame] | 1550 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1551 | if (sc->sc_ah->sw_mgmt_crypto && |
| 1552 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 1553 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
Jouni Malinen | 6ace289 | 2008-12-17 13:32:17 +0200 | [diff] [blame] | 1554 | ret = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1555 | } |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1556 | if (an && key->hw_key_idx) { |
| 1557 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1558 | if (an->key_idx[i]) |
| 1559 | continue; |
| 1560 | an->key_idx[i] = key->hw_key_idx; |
| 1561 | break; |
| 1562 | } |
| 1563 | WARN_ON(i == ARRAY_SIZE(an->key_idx)); |
| 1564 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | case DISABLE_KEY: |
Bruno Randolf | 040e539 | 2010-09-08 16:05:04 +0900 | [diff] [blame] | 1567 | ath_key_delete(common, key); |
Rajkumar Manoharan | 4bbf441 | 2014-05-22 12:35:49 +0530 | [diff] [blame] | 1568 | if (an) { |
| 1569 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1570 | if (an->key_idx[i] != key->hw_key_idx) |
| 1571 | continue; |
| 1572 | an->key_idx[i] = 0; |
| 1573 | break; |
| 1574 | } |
| 1575 | } |
| 1576 | key->hw_key_idx = 0; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1577 | break; |
| 1578 | default: |
| 1579 | ret = -EINVAL; |
| 1580 | } |
| 1581 | |
Vivek Natarajan | 3cbb5dd | 2009-01-20 11:17:08 +0530 | [diff] [blame] | 1582 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1583 | mutex_unlock(&sc->mutex); |
| 1584 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1585 | return ret; |
| 1586 | } |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1587 | |
| 1588 | static void ath9k_set_assoc_state(struct ath_softc *sc, |
| 1589 | struct ieee80211_vif *vif) |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1590 | { |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1591 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1592 | struct ath_vif *avp = (void *)vif->drv_priv; |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1593 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Sujith Manoharan | 07c15a3 | 2012-06-04 20:24:07 +0530 | [diff] [blame] | 1594 | unsigned long flags; |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1595 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1596 | set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1597 | avp->primary_sta_vif = true; |
| 1598 | |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1599 | /* |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1600 | * Set the AID, BSSID and do beacon-sync only when |
| 1601 | * the HW opmode is STATION. |
| 1602 | * |
| 1603 | * But the primary bit is set above in any case. |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1604 | */ |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1605 | if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION) |
| 1606 | return; |
| 1607 | |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1608 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1609 | common->curaid = bss_conf->aid; |
| 1610 | ath9k_hw_write_associd(sc->sc_ah); |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1611 | |
Oleksij Rempel | 32efb0c | 2014-02-04 10:27:39 +0100 | [diff] [blame] | 1612 | common->last_rssi = ATH_RSSI_DUMMY_MARKER; |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1613 | sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1614 | |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1615 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 1616 | sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; |
| 1617 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 1618 | |
Rajkumar Manoharan | 50072eb | 2012-10-12 14:07:22 +0530 | [diff] [blame] | 1619 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 1620 | ath9k_mci_update_wlan_channels(sc, false); |
| 1621 | |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1622 | ath_dbg(common, CONFIG, |
| 1623 | "Primary Station interface: %pM, BSSID: %pM\n", |
| 1624 | vif->addr, common->curbssid); |
| 1625 | } |
| 1626 | |
| 1627 | static void ath9k_bss_assoc_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 1628 | { |
| 1629 | struct ath_softc *sc = data; |
| 1630 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1631 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1632 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1633 | if (test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1634 | return; |
| 1635 | |
| 1636 | if (bss_conf->assoc) |
| 1637 | ath9k_set_assoc_state(sc, vif); |
Rajkumar Manoharan | 4f5ef75b | 2011-04-04 22:56:18 +0530 | [diff] [blame] | 1638 | } |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1639 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1640 | void ath9k_p2p_ps_timer(void *priv) |
| 1641 | { |
| 1642 | struct ath_softc *sc = priv; |
| 1643 | struct ath_vif *avp = sc->p2p_ps_vif; |
| 1644 | struct ieee80211_vif *vif; |
| 1645 | struct ieee80211_sta *sta; |
| 1646 | struct ath_node *an; |
| 1647 | u32 tsf; |
| 1648 | |
| 1649 | if (!avp) |
| 1650 | return; |
| 1651 | |
| 1652 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1653 | if (!avp->noa.absent) |
| 1654 | tsf += ATH_P2P_PS_STOP_TIME; |
| 1655 | |
| 1656 | if (!avp->noa.has_next_tsf || |
| 1657 | avp->noa.next_tsf - tsf > BIT(31)) |
| 1658 | ieee80211_update_p2p_noa(&avp->noa, tsf); |
| 1659 | |
| 1660 | ath9k_update_p2p_ps_timer(sc, avp); |
| 1661 | |
| 1662 | rcu_read_lock(); |
| 1663 | |
| 1664 | vif = avp->vif; |
| 1665 | sta = ieee80211_find_sta(vif, vif->bss_conf.bssid); |
| 1666 | if (!sta) |
| 1667 | goto out; |
| 1668 | |
| 1669 | an = (void *) sta->drv_priv; |
| 1670 | if (an->sleeping == !!avp->noa.absent) |
| 1671 | goto out; |
| 1672 | |
| 1673 | an->sleeping = avp->noa.absent; |
| 1674 | if (an->sleeping) |
| 1675 | ath_tx_aggr_sleep(sta, sc, an); |
| 1676 | else |
| 1677 | ath_tx_aggr_wakeup(sc, an); |
| 1678 | |
| 1679 | out: |
| 1680 | rcu_read_unlock(); |
| 1681 | } |
| 1682 | |
| 1683 | void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif) |
| 1684 | { |
| 1685 | struct ath_vif *avp = (void *)vif->drv_priv; |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1686 | u32 tsf; |
| 1687 | |
| 1688 | if (!sc->p2p_ps_timer) |
| 1689 | return; |
| 1690 | |
| 1691 | if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p) |
| 1692 | return; |
| 1693 | |
| 1694 | sc->p2p_ps_vif = avp; |
Rajkumar Manoharan | 60ccc10 | 2014-05-27 16:58:02 +0530 | [diff] [blame] | 1695 | tsf = ath9k_hw_gettsf32(sc->sc_ah); |
| 1696 | ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf); |
| 1697 | ath9k_update_p2p_ps_timer(sc, avp); |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1700 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
| 1701 | struct ieee80211_vif *vif, |
| 1702 | struct ieee80211_bss_conf *bss_conf, |
| 1703 | u32 changed) |
| 1704 | { |
Sujith Manoharan | da0d45f | 2012-07-17 17:16:29 +0530 | [diff] [blame] | 1705 | #define CHECK_ANI \ |
| 1706 | (BSS_CHANGED_ASSOC | \ |
| 1707 | BSS_CHANGED_IBSS | \ |
| 1708 | BSS_CHANGED_BEACON_ENABLED) |
| 1709 | |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1710 | struct ath_softc *sc = hw->priv; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1711 | struct ath_hw *ah = sc->sc_ah; |
Luis R. Rodriguez | 1510718 | 2009-09-10 09:22:37 -0700 | [diff] [blame] | 1712 | struct ath_common *common = ath9k_hw_common(ah); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1713 | struct ath_vif *avp = (void *)vif->drv_priv; |
Rajkumar Manoharan | 60ccc10 | 2014-05-27 16:58:02 +0530 | [diff] [blame] | 1714 | unsigned long flags; |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1715 | int slottime; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1716 | |
Felix Fietkau | 96f372c | 2011-04-07 19:07:17 +0200 | [diff] [blame] | 1717 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1718 | mutex_lock(&sc->mutex); |
| 1719 | |
Rajkumar Manoharan | 9f61903 | 2012-03-10 05:06:49 +0530 | [diff] [blame] | 1720 | if (changed & BSS_CHANGED_ASSOC) { |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1721 | ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n", |
| 1722 | bss_conf->bssid, bss_conf->assoc); |
Sujith | c6089cc | 2009-11-16 11:40:48 +0530 | [diff] [blame] | 1723 | |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1724 | if (avp->primary_sta_vif && !bss_conf->assoc) { |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1725 | clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1726 | avp->primary_sta_vif = false; |
| 1727 | |
| 1728 | if (ah->opmode == NL80211_IFTYPE_STATION) |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1729 | clear_bit(ATH_OP_BEACONS, &common->op_flags); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1730 | } |
| 1731 | |
Johannes Berg | 8b2c982 | 2012-11-06 20:23:30 +0100 | [diff] [blame] | 1732 | ieee80211_iterate_active_interfaces_atomic( |
| 1733 | sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1734 | ath9k_bss_assoc_iter, sc); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1735 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1736 | if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags) && |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1737 | ah->opmode == NL80211_IFTYPE_STATION) { |
| 1738 | memset(common->curbssid, 0, ETH_ALEN); |
| 1739 | common->curaid = 0; |
| 1740 | ath9k_hw_write_associd(sc->sc_ah); |
Rajkumar Manoharan | 50072eb | 2012-10-12 14:07:22 +0530 | [diff] [blame] | 1741 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 1742 | ath9k_mci_update_wlan_channels(sc, true); |
Sujith Manoharan | 6c43c090 | 2012-07-17 17:15:50 +0530 | [diff] [blame] | 1743 | } |
Felix Fietkau | c083ce9 | 2014-06-11 16:17:54 +0530 | [diff] [blame] | 1744 | |
| 1745 | ath_chanctx_check_active(sc, avp->chanctx); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1748 | if (changed & BSS_CHANGED_IBSS) { |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1749 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1750 | common->curaid = bss_conf->aid; |
| 1751 | ath9k_hw_write_associd(sc->sc_ah); |
Rajkumar Manoharan | 2e5ef45 | 2011-05-20 17:52:12 +0530 | [diff] [blame] | 1752 | } |
| 1753 | |
Sujith Manoharan | ef4ad63 | 2012-07-17 17:15:56 +0530 | [diff] [blame] | 1754 | if ((changed & BSS_CHANGED_BEACON_ENABLED) || |
Felix Fietkau | c32e4e5 | 2013-12-19 18:01:49 +0100 | [diff] [blame] | 1755 | (changed & BSS_CHANGED_BEACON_INT)) |
| 1756 | ath9k_beacon_config(sc, vif, changed); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1757 | |
Felix Fietkau | 0005baf | 2010-01-15 02:33:40 +0100 | [diff] [blame] | 1758 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1759 | if (bss_conf->use_short_slot) |
| 1760 | slottime = 9; |
| 1761 | else |
| 1762 | slottime = 20; |
| 1763 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1764 | /* |
| 1765 | * Defer update, so that connected stations can adjust |
| 1766 | * their settings at the same time. |
| 1767 | * See beacon.c for more details |
| 1768 | */ |
| 1769 | sc->beacon.slottime = slottime; |
| 1770 | sc->beacon.updateslot = UPDATE; |
| 1771 | } else { |
| 1772 | ah->slottime = slottime; |
| 1773 | ath9k_hw_init_global_settings(ah); |
| 1774 | } |
| 1775 | } |
| 1776 | |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1777 | if (changed & BSS_CHANGED_P2P_PS) { |
| 1778 | spin_lock_bh(&sc->sc_pcu_lock); |
Rajkumar Manoharan | 60ccc10 | 2014-05-27 16:58:02 +0530 | [diff] [blame] | 1779 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 1780 | if (!(sc->ps_flags & PS_BEACON_SYNC)) |
| 1781 | ath9k_update_p2p_ps(sc, vif); |
| 1782 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 1783 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 1784 | } |
| 1785 | |
Sujith Manoharan | da0d45f | 2012-07-17 17:16:29 +0530 | [diff] [blame] | 1786 | if (changed & CHECK_ANI) |
| 1787 | ath_check_ani(sc); |
| 1788 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1789 | mutex_unlock(&sc->mutex); |
Felix Fietkau | 96f372c | 2011-04-07 19:07:17 +0200 | [diff] [blame] | 1790 | ath9k_ps_restore(sc); |
Sujith Manoharan | da0d45f | 2012-07-17 17:16:29 +0530 | [diff] [blame] | 1791 | |
| 1792 | #undef CHECK_ANI |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1795 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1796 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1797 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1798 | u64 tsf; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1799 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1800 | mutex_lock(&sc->mutex); |
Sujith Manoharan | 9abbfb2 | 2010-12-10 11:27:06 +0530 | [diff] [blame] | 1801 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1802 | tsf = ath9k_hw_gettsf64(sc->sc_ah); |
Sujith Manoharan | 9abbfb2 | 2010-12-10 11:27:06 +0530 | [diff] [blame] | 1803 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1804 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1805 | |
| 1806 | return tsf; |
| 1807 | } |
| 1808 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1809 | static void ath9k_set_tsf(struct ieee80211_hw *hw, |
| 1810 | struct ieee80211_vif *vif, |
| 1811 | u64 tsf) |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 1812 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1813 | struct ath_softc *sc = hw->priv; |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 1814 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1815 | mutex_lock(&sc->mutex); |
Sujith Manoharan | 9abbfb2 | 2010-12-10 11:27:06 +0530 | [diff] [blame] | 1816 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1817 | ath9k_hw_settsf64(sc->sc_ah, tsf); |
Sujith Manoharan | 9abbfb2 | 2010-12-10 11:27:06 +0530 | [diff] [blame] | 1818 | ath9k_ps_restore(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1819 | mutex_unlock(&sc->mutex); |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 1822 | static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1823 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1824 | struct ath_softc *sc = hw->priv; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1825 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1826 | mutex_lock(&sc->mutex); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 1827 | |
| 1828 | ath9k_ps_wakeup(sc); |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1829 | ath9k_hw_reset_tsf(sc->sc_ah); |
Luis R. Rodriguez | 21526d5 | 2009-09-09 20:05:39 -0700 | [diff] [blame] | 1830 | ath9k_ps_restore(sc); |
| 1831 | |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1832 | mutex_unlock(&sc->mutex); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
Johannes Berg | c951ad3 | 2009-11-16 12:00:38 +0100 | [diff] [blame] | 1836 | struct ieee80211_vif *vif, |
Sujith | 141b38b | 2009-02-04 08:10:07 +0530 | [diff] [blame] | 1837 | enum ieee80211_ampdu_mlme_action action, |
| 1838 | struct ieee80211_sta *sta, |
Johannes Berg | 0b01f03 | 2011-01-18 13:51:05 +0100 | [diff] [blame] | 1839 | u16 tid, u16 *ssn, u8 buf_size) |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1840 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1841 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 16e2342 | 2013-05-17 12:58:24 +0200 | [diff] [blame] | 1842 | bool flush = false; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1843 | int ret = 0; |
| 1844 | |
Sujith Manoharan | 7ca7c77 | 2013-05-08 05:03:32 +0530 | [diff] [blame] | 1845 | mutex_lock(&sc->mutex); |
Johannes Berg | 85ad181 | 2010-06-10 10:21:49 +0200 | [diff] [blame] | 1846 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1847 | switch (action) { |
| 1848 | case IEEE80211_AMPDU_RX_START: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1849 | break; |
| 1850 | case IEEE80211_AMPDU_RX_STOP: |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1851 | break; |
| 1852 | case IEEE80211_AMPDU_TX_START: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1853 | ath9k_ps_wakeup(sc); |
Felix Fietkau | 231c3a1 | 2010-09-20 19:35:28 +0200 | [diff] [blame] | 1854 | ret = ath_tx_aggr_start(sc, sta, tid, ssn); |
| 1855 | if (!ret) |
| 1856 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1857 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1858 | break; |
Johannes Berg | 18b559d | 2012-07-18 13:51:25 +0200 | [diff] [blame] | 1859 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 1860 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
Felix Fietkau | 16e2342 | 2013-05-17 12:58:24 +0200 | [diff] [blame] | 1861 | flush = true; |
| 1862 | case IEEE80211_AMPDU_TX_STOP_CONT: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1863 | ath9k_ps_wakeup(sc); |
Sujith | f83da96 | 2009-07-23 15:32:37 +0530 | [diff] [blame] | 1864 | ath_tx_aggr_stop(sc, sta, tid); |
Felix Fietkau | 08c96ab | 2013-05-18 21:28:15 +0200 | [diff] [blame] | 1865 | if (!flush) |
Felix Fietkau | 16e2342 | 2013-05-17 12:58:24 +0200 | [diff] [blame] | 1866 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1867 | ath9k_ps_restore(sc); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1868 | break; |
Johannes Berg | b172023 | 2009-03-23 17:28:39 +0100 | [diff] [blame] | 1869 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1870 | ath9k_ps_wakeup(sc); |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 1871 | ath_tx_aggr_resume(sc, sta, tid); |
Luis R. Rodriguez | 8b685ba | 2009-12-23 20:03:29 -0500 | [diff] [blame] | 1872 | ath9k_ps_restore(sc); |
Sujith | 8469cde | 2008-10-29 10:19:28 +0530 | [diff] [blame] | 1873 | break; |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1874 | default: |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1875 | ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n"); |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Sujith Manoharan | 7ca7c77 | 2013-05-08 05:03:32 +0530 | [diff] [blame] | 1878 | mutex_unlock(&sc->mutex); |
Johannes Berg | 85ad181 | 2010-06-10 10:21:49 +0200 | [diff] [blame] | 1879 | |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 1880 | return ret; |
| 1881 | } |
| 1882 | |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 1883 | static int ath9k_get_survey(struct ieee80211_hw *hw, int idx, |
| 1884 | struct survey_info *survey) |
| 1885 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1886 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1887 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 1888 | struct ieee80211_supported_band *sband; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1889 | struct ieee80211_channel *chan; |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1890 | int pos; |
| 1891 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1892 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 1893 | return -EOPNOTSUPP; |
| 1894 | |
Sujith Manoharan | b7cc9b9 | 2013-12-26 08:14:40 +0530 | [diff] [blame] | 1895 | spin_lock_bh(&common->cc_lock); |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1896 | if (idx == 0) |
| 1897 | ath_update_survey_stats(sc); |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 1898 | |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 1899 | sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 1900 | if (sband && idx >= sband->n_channels) { |
| 1901 | idx -= sband->n_channels; |
| 1902 | sband = NULL; |
| 1903 | } |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 1904 | |
Felix Fietkau | 39162db | 2010-09-29 19:12:06 +0200 | [diff] [blame] | 1905 | if (!sband) |
| 1906 | sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 1907 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1908 | if (!sband || idx >= sband->n_channels) { |
Sujith Manoharan | b7cc9b9 | 2013-12-26 08:14:40 +0530 | [diff] [blame] | 1909 | spin_unlock_bh(&common->cc_lock); |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1910 | return -ENOENT; |
Felix Fietkau | 4f1a5a4 | 2010-09-29 17:15:28 +0200 | [diff] [blame] | 1911 | } |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 1912 | |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1913 | chan = &sband->channels[idx]; |
| 1914 | pos = chan->hw_value; |
| 1915 | memcpy(survey, &sc->survey[pos], sizeof(*survey)); |
| 1916 | survey->channel = chan; |
Sujith Manoharan | b7cc9b9 | 2013-12-26 08:14:40 +0530 | [diff] [blame] | 1917 | spin_unlock_bh(&common->cc_lock); |
Felix Fietkau | 3430098 | 2010-10-10 18:21:52 +0200 | [diff] [blame] | 1918 | |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 1919 | return 0; |
| 1920 | } |
| 1921 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1922 | static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class) |
| 1923 | { |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 1924 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1925 | struct ath_hw *ah = sc->sc_ah; |
| 1926 | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 1927 | if (config_enabled(CONFIG_ATH9K_TX99)) |
| 1928 | return; |
| 1929 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1930 | mutex_lock(&sc->mutex); |
| 1931 | ah->coverage_class = coverage_class; |
Mohammed Shafi Shajakhan | 8b2a3827 | 2011-08-24 21:38:07 +0530 | [diff] [blame] | 1932 | |
| 1933 | ath9k_ps_wakeup(sc); |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1934 | ath9k_hw_init_global_settings(ah); |
Mohammed Shafi Shajakhan | 8b2a3827 | 2011-08-24 21:38:07 +0530 | [diff] [blame] | 1935 | ath9k_ps_restore(sc); |
| 1936 | |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 1937 | mutex_unlock(&sc->mutex); |
| 1938 | } |
| 1939 | |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 1940 | static bool ath9k_has_tx_pending(struct ath_softc *sc) |
| 1941 | { |
Geert Uytterhoeven | f783807 | 2014-01-26 11:53:21 +0100 | [diff] [blame] | 1942 | int i, npend = 0; |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 1943 | |
| 1944 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 1945 | if (!ATH_TXQ_SETUP(sc, i)) |
| 1946 | continue; |
| 1947 | |
| 1948 | if (!sc->tx.txq[i].axq_depth) |
| 1949 | continue; |
| 1950 | |
| 1951 | npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]); |
| 1952 | if (npend) |
| 1953 | break; |
| 1954 | } |
| 1955 | |
| 1956 | return !!npend; |
| 1957 | } |
| 1958 | |
Emmanuel Grumbach | 77be2c5 | 2014-03-27 11:30:29 +0200 | [diff] [blame] | 1959 | static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1960 | u32 queues, bool drop) |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 1961 | { |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 1962 | struct ath_softc *sc = hw->priv; |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 1963 | |
| 1964 | mutex_lock(&sc->mutex); |
| 1965 | __ath9k_flush(hw, queues, drop); |
| 1966 | mutex_unlock(&sc->mutex); |
| 1967 | } |
| 1968 | |
| 1969 | void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop) |
| 1970 | { |
| 1971 | struct ath_softc *sc = hw->priv; |
Mohammed Shafi Shajakhan | 99aa55b | 2011-05-06 20:43:11 +0530 | [diff] [blame] | 1972 | struct ath_hw *ah = sc->sc_ah; |
| 1973 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 1974 | int timeout = HZ / 5; /* 200 ms */ |
Rajkumar Manoharan | 2f6fc35 | 2011-04-28 15:31:57 +0530 | [diff] [blame] | 1975 | bool drain_txq; |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 1976 | |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 1977 | cancel_delayed_work_sync(&sc->tx_complete_work); |
| 1978 | |
Mohammed Shafi Shajakhan | 6a6b3f3 | 2011-09-09 10:41:08 +0530 | [diff] [blame] | 1979 | if (ah->ah_flags & AH_UNPLUGGED) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1980 | ath_dbg(common, ANY, "Device has been unplugged!\n"); |
Mohammed Shafi Shajakhan | 6a6b3f3 | 2011-09-09 10:41:08 +0530 | [diff] [blame] | 1981 | return; |
| 1982 | } |
| 1983 | |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 1984 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) { |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 1985 | ath_dbg(common, ANY, "Device not present\n"); |
Mohammed Shafi Shajakhan | 99aa55b | 2011-05-06 20:43:11 +0530 | [diff] [blame] | 1986 | return; |
| 1987 | } |
| 1988 | |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 1989 | if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc), |
| 1990 | timeout) > 0) |
| 1991 | drop = false; |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 1992 | |
Felix Fietkau | 9df0d6a | 2011-11-16 13:08:42 +0100 | [diff] [blame] | 1993 | if (drop) { |
| 1994 | ath9k_ps_wakeup(sc); |
| 1995 | spin_lock_bh(&sc->sc_pcu_lock); |
Felix Fietkau | 1381559 | 2013-01-20 18:51:53 +0100 | [diff] [blame] | 1996 | drain_txq = ath_drain_all_txq(sc); |
Felix Fietkau | 9df0d6a | 2011-11-16 13:08:42 +0100 | [diff] [blame] | 1997 | spin_unlock_bh(&sc->sc_pcu_lock); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 1998 | |
Felix Fietkau | 9df0d6a | 2011-11-16 13:08:42 +0100 | [diff] [blame] | 1999 | if (!drain_txq) |
Felix Fietkau | 1381559 | 2013-01-20 18:51:53 +0100 | [diff] [blame] | 2000 | ath_reset(sc); |
Felix Fietkau | 9adcf44 | 2011-09-03 01:40:26 +0200 | [diff] [blame] | 2001 | |
Felix Fietkau | 9df0d6a | 2011-11-16 13:08:42 +0100 | [diff] [blame] | 2002 | ath9k_ps_restore(sc); |
| 2003 | ieee80211_wake_queues(hw); |
| 2004 | } |
Senthil Balasubramanian | d78f4b3 | 2011-03-23 23:07:22 +0530 | [diff] [blame] | 2005 | |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 2006 | ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0); |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
Vivek Natarajan | 15b91e8 | 2011-04-06 11:41:11 +0530 | [diff] [blame] | 2009 | static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw) |
| 2010 | { |
| 2011 | struct ath_softc *sc = hw->priv; |
| 2012 | int i; |
| 2013 | |
| 2014 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 2015 | if (!ATH_TXQ_SETUP(sc, i)) |
| 2016 | continue; |
| 2017 | |
| 2018 | if (ath9k_has_pending_frames(sc, &sc->tx.txq[i])) |
| 2019 | return true; |
| 2020 | } |
| 2021 | return false; |
| 2022 | } |
| 2023 | |
Mohammed Shafi Shajakhan | 5595f11 | 2011-05-19 18:08:57 +0530 | [diff] [blame] | 2024 | static int ath9k_tx_last_beacon(struct ieee80211_hw *hw) |
Felix Fietkau | ba4903f | 2011-05-17 21:09:54 +0200 | [diff] [blame] | 2025 | { |
| 2026 | struct ath_softc *sc = hw->priv; |
| 2027 | struct ath_hw *ah = sc->sc_ah; |
| 2028 | struct ieee80211_vif *vif; |
| 2029 | struct ath_vif *avp; |
| 2030 | struct ath_buf *bf; |
| 2031 | struct ath_tx_status ts; |
Felix Fietkau | 4286df6 | 2012-02-27 19:58:40 +0100 | [diff] [blame] | 2032 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
Felix Fietkau | ba4903f | 2011-05-17 21:09:54 +0200 | [diff] [blame] | 2033 | int status; |
| 2034 | |
| 2035 | vif = sc->beacon.bslot[0]; |
| 2036 | if (!vif) |
| 2037 | return 0; |
| 2038 | |
Sujith Manoharan | aa45fe9 | 2012-07-17 17:16:03 +0530 | [diff] [blame] | 2039 | if (!vif->bss_conf.enable_beacon) |
Felix Fietkau | ba4903f | 2011-05-17 21:09:54 +0200 | [diff] [blame] | 2040 | return 0; |
| 2041 | |
Sujith Manoharan | aa45fe9 | 2012-07-17 17:16:03 +0530 | [diff] [blame] | 2042 | avp = (void *)vif->drv_priv; |
| 2043 | |
Felix Fietkau | 4286df6 | 2012-02-27 19:58:40 +0100 | [diff] [blame] | 2044 | if (!sc->beacon.tx_processed && !edma) { |
Felix Fietkau | ba4903f | 2011-05-17 21:09:54 +0200 | [diff] [blame] | 2045 | tasklet_disable(&sc->bcon_tasklet); |
| 2046 | |
| 2047 | bf = avp->av_bcbuf; |
| 2048 | if (!bf || !bf->bf_mpdu) |
| 2049 | goto skip; |
| 2050 | |
| 2051 | status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts); |
| 2052 | if (status == -EINPROGRESS) |
| 2053 | goto skip; |
| 2054 | |
| 2055 | sc->beacon.tx_processed = true; |
| 2056 | sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK); |
| 2057 | |
| 2058 | skip: |
| 2059 | tasklet_enable(&sc->bcon_tasklet); |
| 2060 | } |
| 2061 | |
| 2062 | return sc->beacon.tx_last; |
| 2063 | } |
| 2064 | |
Mohammed Shafi Shajakhan | 52c94f4 | 2011-08-20 17:21:42 +0530 | [diff] [blame] | 2065 | static int ath9k_get_stats(struct ieee80211_hw *hw, |
| 2066 | struct ieee80211_low_level_stats *stats) |
| 2067 | { |
| 2068 | struct ath_softc *sc = hw->priv; |
| 2069 | struct ath_hw *ah = sc->sc_ah; |
| 2070 | struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats; |
| 2071 | |
| 2072 | stats->dot11ACKFailureCount = mib_stats->ackrcv_bad; |
| 2073 | stats->dot11RTSFailureCount = mib_stats->rts_bad; |
| 2074 | stats->dot11FCSErrorCount = mib_stats->fcs_bad; |
| 2075 | stats->dot11RTSSuccessCount = mib_stats->rts_good; |
| 2076 | return 0; |
| 2077 | } |
| 2078 | |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 2079 | static u32 fill_chainmask(u32 cap, u32 new) |
| 2080 | { |
| 2081 | u32 filled = 0; |
| 2082 | int i; |
| 2083 | |
| 2084 | for (i = 0; cap && new; i++, cap >>= 1) { |
| 2085 | if (!(cap & BIT(0))) |
| 2086 | continue; |
| 2087 | |
| 2088 | if (new & BIT(0)) |
| 2089 | filled |= BIT(i); |
| 2090 | |
| 2091 | new >>= 1; |
| 2092 | } |
| 2093 | |
| 2094 | return filled; |
| 2095 | } |
| 2096 | |
Felix Fietkau | 5d9c7e3 | 2012-07-15 19:53:30 +0200 | [diff] [blame] | 2097 | static bool validate_antenna_mask(struct ath_hw *ah, u32 val) |
| 2098 | { |
Felix Fietkau | fea92cb | 2013-01-20 21:55:22 +0100 | [diff] [blame] | 2099 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2100 | return true; |
| 2101 | |
Felix Fietkau | 5d9c7e3 | 2012-07-15 19:53:30 +0200 | [diff] [blame] | 2102 | switch (val & 0x7) { |
| 2103 | case 0x1: |
| 2104 | case 0x3: |
| 2105 | case 0x7: |
| 2106 | return true; |
| 2107 | case 0x2: |
| 2108 | return (ah->caps.rx_chainmask == 1); |
| 2109 | default: |
| 2110 | return false; |
| 2111 | } |
| 2112 | } |
| 2113 | |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 2114 | static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 2115 | { |
| 2116 | struct ath_softc *sc = hw->priv; |
| 2117 | struct ath_hw *ah = sc->sc_ah; |
| 2118 | |
Felix Fietkau | 5d9c7e3 | 2012-07-15 19:53:30 +0200 | [diff] [blame] | 2119 | if (ah->caps.rx_chainmask != 1) |
| 2120 | rx_ant |= tx_ant; |
| 2121 | |
| 2122 | if (!validate_antenna_mask(ah, rx_ant) || !tx_ant) |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 2123 | return -EINVAL; |
| 2124 | |
| 2125 | sc->ant_rx = rx_ant; |
| 2126 | sc->ant_tx = tx_ant; |
| 2127 | |
| 2128 | if (ah->caps.rx_chainmask == 1) |
| 2129 | return 0; |
| 2130 | |
| 2131 | /* AR9100 runs into calibration issues if not all rx chains are enabled */ |
| 2132 | if (AR_SREV_9100(ah)) |
| 2133 | ah->rxchainmask = 0x7; |
| 2134 | else |
| 2135 | ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant); |
| 2136 | |
| 2137 | ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant); |
Oleksij Rempel | b57ba3b | 2014-02-25 14:48:55 +0100 | [diff] [blame] | 2138 | ath9k_cmn_reload_chainmask(ah); |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 2139 | |
| 2140 | return 0; |
| 2141 | } |
| 2142 | |
| 2143 | static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 2144 | { |
| 2145 | struct ath_softc *sc = hw->priv; |
| 2146 | |
| 2147 | *tx_ant = sc->ant_tx; |
| 2148 | *rx_ant = sc->ant_rx; |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 2152 | static void ath9k_sw_scan_start(struct ieee80211_hw *hw) |
| 2153 | { |
| 2154 | struct ath_softc *sc = hw->priv; |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 2155 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2156 | set_bit(ATH_OP_SCANNING, &common->op_flags); |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static void ath9k_sw_scan_complete(struct ieee80211_hw *hw) |
| 2160 | { |
| 2161 | struct ath_softc *sc = hw->priv; |
Oleksij Rempel | eefa01d | 2014-02-27 11:40:46 +0100 | [diff] [blame] | 2162 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2163 | clear_bit(ATH_OP_SCANNING, &common->op_flags); |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 2164 | } |
Mohammed Shafi Shajakhan | b11e640 | 2012-07-10 14:56:52 +0530 | [diff] [blame] | 2165 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2166 | static void |
| 2167 | ath_scan_next_channel(struct ath_softc *sc) |
| 2168 | { |
| 2169 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 2170 | struct ieee80211_channel *chan; |
| 2171 | |
| 2172 | if (sc->offchannel.scan_idx >= req->n_channels) { |
| 2173 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2174 | ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), |
| 2175 | NULL); |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | chan = req->channels[sc->offchannel.scan_idx++]; |
| 2180 | sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND; |
| 2181 | ath_chanctx_offchan_switch(sc, chan); |
| 2182 | } |
| 2183 | |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2184 | static void ath_offchannel_next(struct ath_softc *sc) |
| 2185 | { |
| 2186 | struct ieee80211_vif *vif; |
| 2187 | |
| 2188 | if (sc->offchannel.scan_req) { |
| 2189 | vif = sc->offchannel.scan_vif; |
| 2190 | sc->offchannel.chan.txpower = vif->bss_conf.txpower; |
| 2191 | ath_scan_next_channel(sc); |
| 2192 | } else if (sc->offchannel.roc_vif) { |
| 2193 | vif = sc->offchannel.roc_vif; |
| 2194 | sc->offchannel.chan.txpower = vif->bss_conf.txpower; |
| 2195 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_START; |
| 2196 | ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan); |
| 2197 | } else { |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2198 | ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), |
| 2199 | NULL); |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2200 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
| 2201 | if (sc->ps_idle) |
| 2202 | ath_cancel_work(sc); |
| 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | static void ath_roc_complete(struct ath_softc *sc, bool abort) |
| 2207 | { |
| 2208 | sc->offchannel.roc_vif = NULL; |
| 2209 | sc->offchannel.roc_chan = NULL; |
| 2210 | if (!abort) |
| 2211 | ieee80211_remain_on_channel_expired(sc->hw); |
| 2212 | ath_offchannel_next(sc); |
| 2213 | ath9k_ps_restore(sc); |
| 2214 | } |
| 2215 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2216 | static void ath_scan_complete(struct ath_softc *sc, bool abort) |
| 2217 | { |
| 2218 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2219 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2220 | sc->offchannel.scan_req = NULL; |
| 2221 | sc->offchannel.scan_vif = NULL; |
| 2222 | sc->offchannel.state = ATH_OFFCHANNEL_IDLE; |
| 2223 | ieee80211_scan_completed(sc->hw, abort); |
| 2224 | clear_bit(ATH_OP_SCANNING, &common->op_flags); |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2225 | ath_offchannel_next(sc); |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2226 | ath9k_ps_restore(sc); |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | static void ath_scan_send_probe(struct ath_softc *sc, |
| 2230 | struct cfg80211_ssid *ssid) |
| 2231 | { |
| 2232 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 2233 | struct ieee80211_vif *vif = sc->offchannel.scan_vif; |
| 2234 | struct ath_tx_control txctl = {}; |
| 2235 | struct sk_buff *skb; |
| 2236 | struct ieee80211_tx_info *info; |
| 2237 | int band = sc->offchannel.chan.chandef.chan->band; |
| 2238 | |
| 2239 | skb = ieee80211_probereq_get(sc->hw, vif, |
| 2240 | ssid->ssid, ssid->ssid_len, req->ie_len); |
| 2241 | if (!skb) |
| 2242 | return; |
| 2243 | |
| 2244 | info = IEEE80211_SKB_CB(skb); |
| 2245 | if (req->no_cck) |
| 2246 | info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE; |
| 2247 | |
| 2248 | if (req->ie_len) |
| 2249 | memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len); |
| 2250 | |
| 2251 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 2252 | |
| 2253 | if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL)) |
| 2254 | goto error; |
| 2255 | |
| 2256 | txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; |
| 2257 | txctl.force_channel = true; |
| 2258 | if (ath_tx_start(sc->hw, skb, &txctl)) |
| 2259 | goto error; |
| 2260 | |
| 2261 | return; |
| 2262 | |
| 2263 | error: |
| 2264 | ieee80211_free_txskb(sc->hw, skb); |
| 2265 | } |
| 2266 | |
| 2267 | static void ath_scan_channel_start(struct ath_softc *sc) |
| 2268 | { |
| 2269 | struct cfg80211_scan_request *req = sc->offchannel.scan_req; |
| 2270 | int i, dwell; |
| 2271 | |
| 2272 | if ((sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) || |
| 2273 | !req->n_ssids) { |
| 2274 | dwell = HZ / 9; /* ~110 ms */ |
| 2275 | } else { |
| 2276 | dwell = HZ / 16; /* ~60 ms */ |
| 2277 | |
| 2278 | for (i = 0; i < req->n_ssids; i++) |
| 2279 | ath_scan_send_probe(sc, &req->ssids[i]); |
| 2280 | } |
| 2281 | |
| 2282 | sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT; |
| 2283 | mod_timer(&sc->offchannel.timer, jiffies + dwell); |
| 2284 | } |
| 2285 | |
| 2286 | void ath_offchannel_channel_change(struct ath_softc *sc) |
| 2287 | { |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2288 | switch (sc->offchannel.state) { |
| 2289 | case ATH_OFFCHANNEL_PROBE_SEND: |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2290 | if (!sc->offchannel.scan_req) |
| 2291 | return; |
| 2292 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2293 | if (sc->cur_chan->chandef.chan != |
| 2294 | sc->offchannel.chan.chandef.chan) |
| 2295 | return; |
| 2296 | |
| 2297 | ath_scan_channel_start(sc); |
| 2298 | break; |
| 2299 | case ATH_OFFCHANNEL_IDLE: |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2300 | if (!sc->offchannel.scan_req) |
| 2301 | return; |
| 2302 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2303 | ath_scan_complete(sc, false); |
| 2304 | break; |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2305 | case ATH_OFFCHANNEL_ROC_START: |
| 2306 | if (sc->cur_chan != &sc->offchannel.chan) |
| 2307 | break; |
| 2308 | |
| 2309 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT; |
| 2310 | mod_timer(&sc->offchannel.timer, jiffies + |
| 2311 | msecs_to_jiffies(sc->offchannel.roc_duration)); |
| 2312 | ieee80211_ready_on_channel(sc->hw); |
| 2313 | break; |
| 2314 | case ATH_OFFCHANNEL_ROC_DONE: |
| 2315 | ath_roc_complete(sc, false); |
| 2316 | break; |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2317 | default: |
| 2318 | break; |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | void ath_offchannel_timer(unsigned long data) |
| 2323 | { |
| 2324 | struct ath_softc *sc = (struct ath_softc *)data; |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2325 | struct ath_chanctx *ctx; |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2326 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2327 | switch (sc->offchannel.state) { |
| 2328 | case ATH_OFFCHANNEL_PROBE_WAIT: |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2329 | if (!sc->offchannel.scan_req) |
| 2330 | return; |
| 2331 | |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2332 | /* get first active channel context */ |
| 2333 | ctx = ath_chanctx_get_oper_chan(sc, true); |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2334 | if (ctx->active) { |
| 2335 | sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND; |
| 2336 | ath_chanctx_switch(sc, ctx, NULL); |
| 2337 | mod_timer(&sc->offchannel.timer, jiffies + HZ / 10); |
| 2338 | break; |
| 2339 | } |
| 2340 | /* fall through */ |
| 2341 | case ATH_OFFCHANNEL_SUSPEND: |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2342 | if (!sc->offchannel.scan_req) |
| 2343 | return; |
| 2344 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2345 | ath_scan_next_channel(sc); |
| 2346 | break; |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2347 | case ATH_OFFCHANNEL_ROC_START: |
| 2348 | case ATH_OFFCHANNEL_ROC_WAIT: |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2349 | ctx = ath_chanctx_get_oper_chan(sc, false); |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2350 | sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE; |
| 2351 | ath_chanctx_switch(sc, ctx, NULL); |
| 2352 | break; |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2353 | default: |
| 2354 | break; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 2359 | struct cfg80211_scan_request *req) |
| 2360 | { |
| 2361 | struct ath_softc *sc = hw->priv; |
| 2362 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2363 | int ret = 0; |
| 2364 | |
| 2365 | mutex_lock(&sc->mutex); |
| 2366 | |
| 2367 | if (WARN_ON(sc->offchannel.scan_req)) { |
| 2368 | ret = -EBUSY; |
| 2369 | goto out; |
| 2370 | } |
| 2371 | |
| 2372 | ath9k_ps_wakeup(sc); |
| 2373 | set_bit(ATH_OP_SCANNING, &common->op_flags); |
| 2374 | sc->offchannel.scan_vif = vif; |
| 2375 | sc->offchannel.scan_req = req; |
| 2376 | sc->offchannel.scan_idx = 0; |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2377 | |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2378 | if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) |
| 2379 | ath_offchannel_next(sc); |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2380 | |
| 2381 | out: |
| 2382 | mutex_unlock(&sc->mutex); |
| 2383 | |
| 2384 | return ret; |
| 2385 | } |
| 2386 | |
| 2387 | static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 2388 | struct ieee80211_vif *vif) |
| 2389 | { |
| 2390 | struct ath_softc *sc = hw->priv; |
| 2391 | |
| 2392 | mutex_lock(&sc->mutex); |
| 2393 | del_timer_sync(&sc->offchannel.timer); |
| 2394 | ath_scan_complete(sc, true); |
| 2395 | mutex_unlock(&sc->mutex); |
| 2396 | } |
| 2397 | |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2398 | static int ath9k_remain_on_channel(struct ieee80211_hw *hw, |
| 2399 | struct ieee80211_vif *vif, |
| 2400 | struct ieee80211_channel *chan, int duration, |
| 2401 | enum ieee80211_roc_type type) |
| 2402 | { |
| 2403 | struct ath_softc *sc = hw->priv; |
| 2404 | int ret = 0; |
| 2405 | |
| 2406 | mutex_lock(&sc->mutex); |
| 2407 | |
| 2408 | if (WARN_ON(sc->offchannel.roc_vif)) { |
| 2409 | ret = -EBUSY; |
| 2410 | goto out; |
| 2411 | } |
| 2412 | |
| 2413 | ath9k_ps_wakeup(sc); |
| 2414 | sc->offchannel.roc_vif = vif; |
| 2415 | sc->offchannel.roc_chan = chan; |
| 2416 | sc->offchannel.roc_duration = duration; |
| 2417 | |
| 2418 | if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) |
| 2419 | ath_offchannel_next(sc); |
| 2420 | |
| 2421 | out: |
| 2422 | mutex_unlock(&sc->mutex); |
| 2423 | |
| 2424 | return ret; |
| 2425 | } |
| 2426 | |
| 2427 | static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw) |
| 2428 | { |
| 2429 | struct ath_softc *sc = hw->priv; |
| 2430 | |
| 2431 | mutex_lock(&sc->mutex); |
| 2432 | |
| 2433 | del_timer_sync(&sc->offchannel.timer); |
| 2434 | |
| 2435 | if (sc->offchannel.roc_vif) { |
| 2436 | if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START) |
| 2437 | ath_roc_complete(sc, true); |
| 2438 | } |
| 2439 | |
| 2440 | mutex_unlock(&sc->mutex); |
| 2441 | |
| 2442 | return 0; |
| 2443 | } |
| 2444 | |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2445 | static int ath9k_add_chanctx(struct ieee80211_hw *hw, |
| 2446 | struct ieee80211_chanctx_conf *conf) |
| 2447 | { |
| 2448 | struct ath_softc *sc = hw->priv; |
| 2449 | struct ath_chanctx *ctx, **ptr; |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2450 | |
| 2451 | mutex_lock(&sc->mutex); |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2452 | |
| 2453 | ath_for_each_chanctx(sc, ctx) { |
| 2454 | if (ctx->assigned) |
| 2455 | continue; |
| 2456 | |
| 2457 | ptr = (void *) conf->drv_priv; |
| 2458 | *ptr = ctx; |
| 2459 | ctx->assigned = true; |
| 2460 | ath_chanctx_set_channel(sc, ctx, &conf->def); |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2461 | mutex_unlock(&sc->mutex); |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2462 | return 0; |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2463 | } |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2464 | mutex_unlock(&sc->mutex); |
Rajkumar Manoharan | c4dc0d0 | 2014-06-11 16:17:58 +0530 | [diff] [blame] | 2465 | return -ENOSPC; |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | static void ath9k_remove_chanctx(struct ieee80211_hw *hw, |
| 2470 | struct ieee80211_chanctx_conf *conf) |
| 2471 | { |
| 2472 | struct ath_softc *sc = hw->priv; |
| 2473 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2474 | |
| 2475 | mutex_lock(&sc->mutex); |
| 2476 | ctx->assigned = false; |
| 2477 | mutex_unlock(&sc->mutex); |
| 2478 | } |
| 2479 | |
| 2480 | static void ath9k_change_chanctx(struct ieee80211_hw *hw, |
| 2481 | struct ieee80211_chanctx_conf *conf, |
| 2482 | u32 changed) |
| 2483 | { |
| 2484 | struct ath_softc *sc = hw->priv; |
| 2485 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2486 | |
| 2487 | mutex_lock(&sc->mutex); |
| 2488 | ath_chanctx_set_channel(sc, ctx, &conf->def); |
| 2489 | mutex_unlock(&sc->mutex); |
| 2490 | } |
| 2491 | |
| 2492 | static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 2493 | struct ieee80211_vif *vif, |
| 2494 | struct ieee80211_chanctx_conf *conf) |
| 2495 | { |
| 2496 | struct ath_softc *sc = hw->priv; |
| 2497 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2498 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2499 | |
| 2500 | mutex_lock(&sc->mutex); |
| 2501 | avp->chanctx = ctx; |
| 2502 | list_add_tail(&avp->list, &ctx->vifs); |
| 2503 | ath_chanctx_check_active(sc, ctx); |
| 2504 | mutex_unlock(&sc->mutex); |
| 2505 | |
| 2506 | return 0; |
| 2507 | } |
| 2508 | |
| 2509 | static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 2510 | struct ieee80211_vif *vif, |
| 2511 | struct ieee80211_chanctx_conf *conf) |
| 2512 | { |
| 2513 | struct ath_softc *sc = hw->priv; |
| 2514 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2515 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2516 | |
| 2517 | mutex_lock(&sc->mutex); |
| 2518 | avp->chanctx = NULL; |
| 2519 | list_del(&avp->list); |
| 2520 | ath_chanctx_check_active(sc, ctx); |
| 2521 | mutex_unlock(&sc->mutex); |
| 2522 | } |
| 2523 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2524 | void ath9k_fill_chanctx_ops(void) |
| 2525 | { |
| 2526 | if (!ath9k_use_chanctx) |
| 2527 | return; |
| 2528 | |
| 2529 | ath9k_ops.hw_scan = ath9k_hw_scan; |
| 2530 | ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan; |
Felix Fietkau | 405393c | 2014-06-11 16:17:56 +0530 | [diff] [blame] | 2531 | ath9k_ops.remain_on_channel = ath9k_remain_on_channel; |
| 2532 | ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel; |
Felix Fietkau | 3930563 | 2014-06-11 16:17:57 +0530 | [diff] [blame] | 2533 | ath9k_ops.add_chanctx = ath9k_add_chanctx; |
| 2534 | ath9k_ops.remove_chanctx = ath9k_remove_chanctx; |
| 2535 | ath9k_ops.change_chanctx = ath9k_change_chanctx; |
| 2536 | ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx; |
| 2537 | ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx; |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 2538 | } |
| 2539 | |
Gabor Juhos | 6baff7f | 2009-01-14 20:17:06 +0100 | [diff] [blame] | 2540 | struct ieee80211_ops ath9k_ops = { |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2541 | .tx = ath9k_tx, |
| 2542 | .start = ath9k_start, |
| 2543 | .stop = ath9k_stop, |
| 2544 | .add_interface = ath9k_add_interface, |
Rajkumar Manoharan | 6b3b991 | 2010-12-08 19:38:55 +0530 | [diff] [blame] | 2545 | .change_interface = ath9k_change_interface, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2546 | .remove_interface = ath9k_remove_interface, |
| 2547 | .config = ath9k_config, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2548 | .configure_filter = ath9k_configure_filter, |
Johannes Berg | 4ca7786 | 2010-02-19 19:06:56 +0100 | [diff] [blame] | 2549 | .sta_add = ath9k_sta_add, |
| 2550 | .sta_remove = ath9k_sta_remove, |
Felix Fietkau | 5519541 | 2011-04-17 23:28:09 +0200 | [diff] [blame] | 2551 | .sta_notify = ath9k_sta_notify, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2552 | .conf_tx = ath9k_conf_tx, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2553 | .bss_info_changed = ath9k_bss_info_changed, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2554 | .set_key = ath9k_set_key, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2555 | .get_tsf = ath9k_get_tsf, |
Alina Friedrichsen | 3b5d665 | 2009-01-24 07:09:59 +0100 | [diff] [blame] | 2556 | .set_tsf = ath9k_set_tsf, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2557 | .reset_tsf = ath9k_reset_tsf, |
Johannes Berg | 4233df6 | 2008-10-13 13:35:05 +0200 | [diff] [blame] | 2558 | .ampdu_action = ath9k_ampdu_action, |
Benoit Papillault | 62dad5b | 2010-04-28 00:08:24 +0200 | [diff] [blame] | 2559 | .get_survey = ath9k_get_survey, |
Johannes Berg | 3b319aa | 2009-06-13 14:50:26 +0530 | [diff] [blame] | 2560 | .rfkill_poll = ath9k_rfkill_poll_state, |
Felix Fietkau | e239d85 | 2010-01-15 02:34:58 +0100 | [diff] [blame] | 2561 | .set_coverage_class = ath9k_set_coverage_class, |
Vasanthakumar Thiagarajan | 6908162 | 2011-02-19 01:13:42 -0800 | [diff] [blame] | 2562 | .flush = ath9k_flush, |
Vivek Natarajan | 15b91e8 | 2011-04-06 11:41:11 +0530 | [diff] [blame] | 2563 | .tx_frames_pending = ath9k_tx_frames_pending, |
Mohammed Shafi Shajakhan | 52c94f4 | 2011-08-20 17:21:42 +0530 | [diff] [blame] | 2564 | .tx_last_beacon = ath9k_tx_last_beacon, |
Felix Fietkau | 86a22ac | 2013-06-07 18:12:01 +0200 | [diff] [blame] | 2565 | .release_buffered_frames = ath9k_release_buffered_frames, |
Mohammed Shafi Shajakhan | 52c94f4 | 2011-08-20 17:21:42 +0530 | [diff] [blame] | 2566 | .get_stats = ath9k_get_stats, |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 2567 | .set_antenna = ath9k_set_antenna, |
| 2568 | .get_antenna = ath9k_get_antenna, |
Ben Greear | b90bd9d | 2012-05-15 15:33:25 -0700 | [diff] [blame] | 2569 | |
Sujith Manoharan | e60001e | 2013-10-28 12:22:04 +0530 | [diff] [blame] | 2570 | #ifdef CONFIG_ATH9K_WOW |
Mohammed Shafi Shajakhan | b11e640 | 2012-07-10 14:56:52 +0530 | [diff] [blame] | 2571 | .suspend = ath9k_suspend, |
| 2572 | .resume = ath9k_resume, |
| 2573 | .set_wakeup = ath9k_set_wakeup, |
| 2574 | #endif |
| 2575 | |
Ben Greear | b90bd9d | 2012-05-15 15:33:25 -0700 | [diff] [blame] | 2576 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 2577 | .get_et_sset_count = ath9k_get_et_sset_count, |
Sujith Manoharan | a145daf | 2012-11-28 15:08:54 +0530 | [diff] [blame] | 2578 | .get_et_stats = ath9k_get_et_stats, |
| 2579 | .get_et_strings = ath9k_get_et_strings, |
| 2580 | #endif |
| 2581 | |
Sujith Manoharan | 1cdbaf0 | 2014-01-13 07:29:27 +0530 | [diff] [blame] | 2582 | #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS) |
Sujith Manoharan | a145daf | 2012-11-28 15:08:54 +0530 | [diff] [blame] | 2583 | .sta_add_debugfs = ath9k_sta_add_debugfs, |
Ben Greear | b90bd9d | 2012-05-15 15:33:25 -0700 | [diff] [blame] | 2584 | #endif |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 2585 | .sw_scan_start = ath9k_sw_scan_start, |
| 2586 | .sw_scan_complete = ath9k_sw_scan_complete, |
Luis R. Rodriguez | f078f20 | 2008-08-04 00:16:41 -0700 | [diff] [blame] | 2587 | }; |