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