b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
| 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 | |
| 17 | #include <linux/nl80211.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include "ath9k.h" |
| 20 | #include "btcoex.h" |
| 21 | |
| 22 | u8 ath9k_parse_mpdudensity(u8 mpdudensity) |
| 23 | { |
| 24 | /* |
| 25 | * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing": |
| 26 | * 0 for no restriction |
| 27 | * 1 for 1/4 us |
| 28 | * 2 for 1/2 us |
| 29 | * 3 for 1 us |
| 30 | * 4 for 2 us |
| 31 | * 5 for 4 us |
| 32 | * 6 for 8 us |
| 33 | * 7 for 16 us |
| 34 | */ |
| 35 | switch (mpdudensity) { |
| 36 | case 0: |
| 37 | return 0; |
| 38 | case 1: |
| 39 | case 2: |
| 40 | case 3: |
| 41 | /* Our lower layer calculations limit our precision to |
| 42 | 1 microsecond */ |
| 43 | return 1; |
| 44 | case 4: |
| 45 | return 2; |
| 46 | case 5: |
| 47 | return 4; |
| 48 | case 6: |
| 49 | return 8; |
| 50 | case 7: |
| 51 | return 16; |
| 52 | default: |
| 53 | return 0; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq, |
| 58 | bool sw_pending) |
| 59 | { |
| 60 | bool pending = false; |
| 61 | |
| 62 | spin_lock_bh(&txq->axq_lock); |
| 63 | |
| 64 | if (txq->axq_depth) { |
| 65 | pending = true; |
| 66 | goto out; |
| 67 | } |
| 68 | |
| 69 | if (!sw_pending) |
| 70 | goto out; |
| 71 | |
| 72 | if (txq->mac80211_qnum >= 0) { |
| 73 | struct ath_acq *acq; |
| 74 | |
| 75 | acq = &sc->cur_chan->acq[txq->mac80211_qnum]; |
| 76 | if (!list_empty(&acq->acq_new) || !list_empty(&acq->acq_old)) |
| 77 | pending = true; |
| 78 | } |
| 79 | out: |
| 80 | spin_unlock_bh(&txq->axq_lock); |
| 81 | return pending; |
| 82 | } |
| 83 | |
| 84 | static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode) |
| 85 | { |
| 86 | unsigned long flags; |
| 87 | bool ret; |
| 88 | |
| 89 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 90 | ret = ath9k_hw_setpower(sc->sc_ah, mode); |
| 91 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | void ath_ps_full_sleep(struct timer_list *t) |
| 97 | { |
| 98 | struct ath_softc *sc = from_timer(sc, t, sleep_timer); |
| 99 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 100 | unsigned long flags; |
| 101 | bool reset; |
| 102 | |
| 103 | spin_lock_irqsave(&common->cc_lock, flags); |
| 104 | ath_hw_cycle_counters_update(common); |
| 105 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 106 | |
| 107 | ath9k_hw_setrxabort(sc->sc_ah, 1); |
| 108 | ath9k_hw_stopdmarecv(sc->sc_ah, &reset); |
| 109 | |
| 110 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); |
| 111 | } |
| 112 | |
| 113 | void ath9k_ps_wakeup(struct ath_softc *sc) |
| 114 | { |
| 115 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 116 | unsigned long flags; |
| 117 | enum ath9k_power_mode power_mode; |
| 118 | |
| 119 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 120 | if (++sc->ps_usecount != 1) |
| 121 | goto unlock; |
| 122 | |
| 123 | del_timer_sync(&sc->sleep_timer); |
| 124 | power_mode = sc->sc_ah->power_mode; |
| 125 | ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE); |
| 126 | |
| 127 | /* |
| 128 | * While the hardware is asleep, the cycle counters contain no |
| 129 | * useful data. Better clear them now so that they don't mess up |
| 130 | * survey data results. |
| 131 | */ |
| 132 | if (power_mode != ATH9K_PM_AWAKE) { |
| 133 | spin_lock(&common->cc_lock); |
| 134 | ath_hw_cycle_counters_update(common); |
| 135 | memset(&common->cc_survey, 0, sizeof(common->cc_survey)); |
| 136 | memset(&common->cc_ani, 0, sizeof(common->cc_ani)); |
| 137 | spin_unlock(&common->cc_lock); |
| 138 | } |
| 139 | |
| 140 | unlock: |
| 141 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 142 | } |
| 143 | |
| 144 | void ath9k_ps_restore(struct ath_softc *sc) |
| 145 | { |
| 146 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 147 | enum ath9k_power_mode mode; |
| 148 | unsigned long flags; |
| 149 | |
| 150 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 151 | if (--sc->ps_usecount != 0) |
| 152 | goto unlock; |
| 153 | |
| 154 | if (sc->ps_idle) { |
| 155 | mod_timer(&sc->sleep_timer, jiffies + HZ / 10); |
| 156 | goto unlock; |
| 157 | } |
| 158 | |
| 159 | if (sc->ps_enabled && |
| 160 | !(sc->ps_flags & (PS_WAIT_FOR_BEACON | |
| 161 | PS_WAIT_FOR_CAB | |
| 162 | PS_WAIT_FOR_PSPOLL_DATA | |
| 163 | PS_WAIT_FOR_TX_ACK | |
| 164 | PS_WAIT_FOR_ANI))) { |
| 165 | mode = ATH9K_PM_NETWORK_SLEEP; |
| 166 | if (ath9k_hw_btcoex_is_enabled(sc->sc_ah)) |
| 167 | ath9k_btcoex_stop_gen_timer(sc); |
| 168 | } else { |
| 169 | goto unlock; |
| 170 | } |
| 171 | |
| 172 | spin_lock(&common->cc_lock); |
| 173 | ath_hw_cycle_counters_update(common); |
| 174 | spin_unlock(&common->cc_lock); |
| 175 | |
| 176 | ath9k_hw_setpower(sc->sc_ah, mode); |
| 177 | |
| 178 | unlock: |
| 179 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 180 | } |
| 181 | |
| 182 | static void __ath_cancel_work(struct ath_softc *sc) |
| 183 | { |
| 184 | cancel_work_sync(&sc->paprd_work); |
| 185 | cancel_delayed_work_sync(&sc->hw_check_work); |
| 186 | cancel_delayed_work_sync(&sc->hw_pll_work); |
| 187 | |
| 188 | #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT |
| 189 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 190 | cancel_work_sync(&sc->mci_work); |
| 191 | #endif |
| 192 | } |
| 193 | |
| 194 | void ath_cancel_work(struct ath_softc *sc) |
| 195 | { |
| 196 | __ath_cancel_work(sc); |
| 197 | cancel_work_sync(&sc->hw_reset_work); |
| 198 | } |
| 199 | |
| 200 | void ath_restart_work(struct ath_softc *sc) |
| 201 | { |
| 202 | ieee80211_queue_delayed_work(sc->hw, &sc->hw_check_work, |
| 203 | msecs_to_jiffies(ATH_HW_CHECK_POLL_INT)); |
| 204 | |
| 205 | if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah)) |
| 206 | ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, |
| 207 | msecs_to_jiffies(ATH_PLL_WORK_INTERVAL)); |
| 208 | |
| 209 | ath_start_ani(sc); |
| 210 | } |
| 211 | |
| 212 | static bool ath_prepare_reset(struct ath_softc *sc) |
| 213 | { |
| 214 | struct ath_hw *ah = sc->sc_ah; |
| 215 | bool ret = true; |
| 216 | |
| 217 | ieee80211_stop_queues(sc->hw); |
| 218 | ath_stop_ani(sc); |
| 219 | ath9k_hw_disable_interrupts(ah); |
| 220 | |
| 221 | if (AR_SREV_9300_20_OR_LATER(ah)) { |
| 222 | ret &= ath_stoprecv(sc); |
| 223 | ret &= ath_drain_all_txq(sc); |
| 224 | } else { |
| 225 | ret &= ath_drain_all_txq(sc); |
| 226 | ret &= ath_stoprecv(sc); |
| 227 | } |
| 228 | |
| 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | static bool ath_complete_reset(struct ath_softc *sc, bool start) |
| 233 | { |
| 234 | struct ath_hw *ah = sc->sc_ah; |
| 235 | struct ath_common *common = ath9k_hw_common(ah); |
| 236 | unsigned long flags; |
| 237 | |
| 238 | ath9k_calculate_summary_state(sc, sc->cur_chan); |
| 239 | ath_startrecv(sc); |
| 240 | ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower, |
| 241 | sc->cur_chan->txpower, |
| 242 | &sc->cur_chan->cur_txpower); |
| 243 | clear_bit(ATH_OP_HW_RESET, &common->op_flags); |
| 244 | |
| 245 | if (!sc->cur_chan->offchannel && start) { |
| 246 | /* restore per chanctx TSF timer */ |
| 247 | if (sc->cur_chan->tsf_val) { |
| 248 | u32 offset; |
| 249 | |
| 250 | offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, |
| 251 | NULL); |
| 252 | ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset); |
| 253 | } |
| 254 | |
| 255 | |
| 256 | if (!test_bit(ATH_OP_BEACONS, &common->op_flags)) |
| 257 | goto work; |
| 258 | |
| 259 | if (ah->opmode == NL80211_IFTYPE_STATION && |
| 260 | test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) { |
| 261 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 262 | sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; |
| 263 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 264 | } else { |
| 265 | ath9k_set_beacon(sc); |
| 266 | } |
| 267 | work: |
| 268 | ath_restart_work(sc); |
| 269 | ath_txq_schedule_all(sc); |
| 270 | } |
| 271 | |
| 272 | sc->gtt_cnt = 0; |
| 273 | |
| 274 | ath9k_hw_set_interrupts(ah); |
| 275 | ath9k_hw_enable_interrupts(ah); |
| 276 | ieee80211_wake_queues(sc->hw); |
| 277 | ath9k_p2p_ps_timer(sc); |
| 278 | |
| 279 | return true; |
| 280 | } |
| 281 | |
| 282 | static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan) |
| 283 | { |
| 284 | struct ath_hw *ah = sc->sc_ah; |
| 285 | struct ath_common *common = ath9k_hw_common(ah); |
| 286 | struct ath9k_hw_cal_data *caldata = NULL; |
| 287 | bool fastcc = true; |
| 288 | int r; |
| 289 | |
| 290 | __ath_cancel_work(sc); |
| 291 | |
| 292 | disable_irq(sc->irq); |
| 293 | tasklet_disable(&sc->intr_tq); |
| 294 | tasklet_disable(&sc->bcon_tasklet); |
| 295 | spin_lock_bh(&sc->sc_pcu_lock); |
| 296 | |
| 297 | if (!sc->cur_chan->offchannel) { |
| 298 | fastcc = false; |
| 299 | caldata = &sc->cur_chan->caldata; |
| 300 | } |
| 301 | |
| 302 | if (!hchan) { |
| 303 | fastcc = false; |
| 304 | hchan = ah->curchan; |
| 305 | } |
| 306 | |
| 307 | if (!hchan) { |
| 308 | fastcc = false; |
| 309 | hchan = ath9k_cmn_get_channel(sc->hw, ah, &sc->cur_chan->chandef); |
| 310 | } |
| 311 | |
| 312 | if (!ath_prepare_reset(sc)) |
| 313 | fastcc = false; |
| 314 | |
| 315 | if (ath9k_is_chanctx_enabled()) |
| 316 | fastcc = false; |
| 317 | |
| 318 | spin_lock_bh(&sc->chan_lock); |
| 319 | sc->cur_chandef = sc->cur_chan->chandef; |
| 320 | spin_unlock_bh(&sc->chan_lock); |
| 321 | |
| 322 | ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n", |
| 323 | hchan->channel, IS_CHAN_HT40(hchan), fastcc); |
| 324 | |
| 325 | r = ath9k_hw_reset(ah, hchan, caldata, fastcc); |
| 326 | if (r) { |
| 327 | ath_err(common, |
| 328 | "Unable to reset channel, reset status %d\n", r); |
| 329 | |
| 330 | ath9k_hw_enable_interrupts(ah); |
| 331 | ath9k_queue_reset(sc, RESET_TYPE_BB_HANG); |
| 332 | |
| 333 | goto out; |
| 334 | } |
| 335 | |
| 336 | if (ath9k_hw_mci_is_enabled(sc->sc_ah) && |
| 337 | sc->cur_chan->offchannel) |
| 338 | ath9k_mci_set_txpower(sc, true, false); |
| 339 | |
| 340 | if (!ath_complete_reset(sc, true)) |
| 341 | r = -EIO; |
| 342 | |
| 343 | out: |
| 344 | enable_irq(sc->irq); |
| 345 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 346 | tasklet_enable(&sc->bcon_tasklet); |
| 347 | tasklet_enable(&sc->intr_tq); |
| 348 | |
| 349 | return r; |
| 350 | } |
| 351 | |
| 352 | static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta, |
| 353 | struct ieee80211_vif *vif) |
| 354 | { |
| 355 | struct ath_node *an; |
| 356 | an = (struct ath_node *)sta->drv_priv; |
| 357 | |
| 358 | an->sc = sc; |
| 359 | an->sta = sta; |
| 360 | an->vif = vif; |
| 361 | memset(&an->key_idx, 0, sizeof(an->key_idx)); |
| 362 | |
| 363 | ath_tx_node_init(sc, an); |
| 364 | |
| 365 | ath_dynack_node_init(sc->sc_ah, an); |
| 366 | } |
| 367 | |
| 368 | static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta) |
| 369 | { |
| 370 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
| 371 | ath_tx_node_cleanup(sc, an); |
| 372 | |
| 373 | ath_dynack_node_deinit(sc->sc_ah, an); |
| 374 | } |
| 375 | |
| 376 | void ath9k_tasklet(unsigned long data) |
| 377 | { |
| 378 | struct ath_softc *sc = (struct ath_softc *)data; |
| 379 | struct ath_hw *ah = sc->sc_ah; |
| 380 | struct ath_common *common = ath9k_hw_common(ah); |
| 381 | enum ath_reset_type type; |
| 382 | unsigned long flags; |
| 383 | u32 status; |
| 384 | u32 rxmask; |
| 385 | |
| 386 | spin_lock_irqsave(&sc->intr_lock, flags); |
| 387 | status = sc->intrstatus; |
| 388 | sc->intrstatus = 0; |
| 389 | spin_unlock_irqrestore(&sc->intr_lock, flags); |
| 390 | |
| 391 | ath9k_ps_wakeup(sc); |
| 392 | spin_lock(&sc->sc_pcu_lock); |
| 393 | |
| 394 | if (status & ATH9K_INT_FATAL) { |
| 395 | type = RESET_TYPE_FATAL_INT; |
| 396 | ath9k_queue_reset(sc, type); |
| 397 | ath_dbg(common, RESET, "FATAL: Skipping interrupts\n"); |
| 398 | goto out; |
| 399 | } |
| 400 | |
| 401 | if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) && |
| 402 | (status & ATH9K_INT_BB_WATCHDOG)) { |
| 403 | spin_lock_irqsave(&common->cc_lock, flags); |
| 404 | ath_hw_cycle_counters_update(common); |
| 405 | ar9003_hw_bb_watchdog_dbg_info(ah); |
| 406 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 407 | |
| 408 | if (ar9003_hw_bb_watchdog_check(ah)) { |
| 409 | type = RESET_TYPE_BB_WATCHDOG; |
| 410 | ath9k_queue_reset(sc, type); |
| 411 | |
| 412 | ath_dbg(common, RESET, |
| 413 | "BB_WATCHDOG: Skipping interrupts\n"); |
| 414 | goto out; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | if (status & ATH9K_INT_GTT) { |
| 419 | sc->gtt_cnt++; |
| 420 | |
| 421 | if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) { |
| 422 | type = RESET_TYPE_TX_GTT; |
| 423 | ath9k_queue_reset(sc, type); |
| 424 | ath_dbg(common, RESET, |
| 425 | "GTT: Skipping interrupts\n"); |
| 426 | goto out; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 431 | if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { |
| 432 | /* |
| 433 | * TSF sync does not look correct; remain awake to sync with |
| 434 | * the next Beacon. |
| 435 | */ |
| 436 | ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n"); |
| 437 | sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC; |
| 438 | } |
| 439 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 440 | |
| 441 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 442 | rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL | |
| 443 | ATH9K_INT_RXORN); |
| 444 | else |
| 445 | rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
| 446 | |
| 447 | if (status & rxmask) { |
| 448 | /* Check for high priority Rx first */ |
| 449 | if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && |
| 450 | (status & ATH9K_INT_RXHP)) |
| 451 | ath_rx_tasklet(sc, 0, true); |
| 452 | |
| 453 | ath_rx_tasklet(sc, 0, false); |
| 454 | } |
| 455 | |
| 456 | if (status & ATH9K_INT_TX) { |
| 457 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 458 | /* |
| 459 | * For EDMA chips, TX completion is enabled for the |
| 460 | * beacon queue, so if a beacon has been transmitted |
| 461 | * successfully after a GTT interrupt, the GTT counter |
| 462 | * gets reset to zero here. |
| 463 | */ |
| 464 | sc->gtt_cnt = 0; |
| 465 | |
| 466 | ath_tx_edma_tasklet(sc); |
| 467 | } else { |
| 468 | ath_tx_tasklet(sc); |
| 469 | } |
| 470 | |
| 471 | wake_up(&sc->tx_wait); |
| 472 | } |
| 473 | |
| 474 | if (status & ATH9K_INT_GENTIMER) |
| 475 | ath_gen_timer_isr(sc->sc_ah); |
| 476 | |
| 477 | ath9k_btcoex_handle_interrupt(sc, status); |
| 478 | |
| 479 | /* re-enable hardware interrupt */ |
| 480 | ath9k_hw_resume_interrupts(ah); |
| 481 | out: |
| 482 | spin_unlock(&sc->sc_pcu_lock); |
| 483 | ath9k_ps_restore(sc); |
| 484 | } |
| 485 | |
| 486 | irqreturn_t ath_isr(int irq, void *dev) |
| 487 | { |
| 488 | #define SCHED_INTR ( \ |
| 489 | ATH9K_INT_FATAL | \ |
| 490 | ATH9K_INT_BB_WATCHDOG | \ |
| 491 | ATH9K_INT_RXORN | \ |
| 492 | ATH9K_INT_RXEOL | \ |
| 493 | ATH9K_INT_RX | \ |
| 494 | ATH9K_INT_RXLP | \ |
| 495 | ATH9K_INT_RXHP | \ |
| 496 | ATH9K_INT_TX | \ |
| 497 | ATH9K_INT_BMISS | \ |
| 498 | ATH9K_INT_CST | \ |
| 499 | ATH9K_INT_GTT | \ |
| 500 | ATH9K_INT_TSFOOR | \ |
| 501 | ATH9K_INT_GENTIMER | \ |
| 502 | ATH9K_INT_MCI) |
| 503 | |
| 504 | struct ath_softc *sc = dev; |
| 505 | struct ath_hw *ah = sc->sc_ah; |
| 506 | struct ath_common *common = ath9k_hw_common(ah); |
| 507 | enum ath9k_int status; |
| 508 | u32 sync_cause = 0; |
| 509 | bool sched = false; |
| 510 | |
| 511 | /* |
| 512 | * The hardware is not ready/present, don't |
| 513 | * touch anything. Note this can happen early |
| 514 | * on if the IRQ is shared. |
| 515 | */ |
| 516 | if (!ah || test_bit(ATH_OP_INVALID, &common->op_flags)) |
| 517 | return IRQ_NONE; |
| 518 | |
| 519 | /* shared irq, not for us */ |
| 520 | if (!ath9k_hw_intrpend(ah)) |
| 521 | return IRQ_NONE; |
| 522 | |
| 523 | /* |
| 524 | * Figure out the reason(s) for the interrupt. Note |
| 525 | * that the hal returns a pseudo-ISR that may include |
| 526 | * bits we haven't explicitly enabled so we mask the |
| 527 | * value to insure we only process bits we requested. |
| 528 | */ |
| 529 | ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */ |
| 530 | ath9k_debug_sync_cause(sc, sync_cause); |
| 531 | status &= ah->imask; /* discard unasked-for bits */ |
| 532 | |
| 533 | if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) { |
| 534 | ath9k_hw_kill_interrupts(sc->sc_ah); |
| 535 | return IRQ_HANDLED; |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | * If there are no status bits set, then this interrupt was not |
| 540 | * for me (should have been caught above). |
| 541 | */ |
| 542 | if (!status) |
| 543 | return IRQ_NONE; |
| 544 | |
| 545 | /* Cache the status */ |
| 546 | spin_lock(&sc->intr_lock); |
| 547 | sc->intrstatus |= status; |
| 548 | spin_unlock(&sc->intr_lock); |
| 549 | |
| 550 | if (status & SCHED_INTR) |
| 551 | sched = true; |
| 552 | |
| 553 | /* |
| 554 | * If a FATAL interrupt is received, we have to reset the chip |
| 555 | * immediately. |
| 556 | */ |
| 557 | if (status & ATH9K_INT_FATAL) |
| 558 | goto chip_reset; |
| 559 | |
| 560 | if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) && |
| 561 | (status & ATH9K_INT_BB_WATCHDOG)) |
| 562 | goto chip_reset; |
| 563 | |
| 564 | if (status & ATH9K_INT_SWBA) |
| 565 | tasklet_schedule(&sc->bcon_tasklet); |
| 566 | |
| 567 | if (status & ATH9K_INT_TXURN) |
| 568 | ath9k_hw_updatetxtriglevel(ah, true); |
| 569 | |
| 570 | if (status & ATH9K_INT_RXEOL) { |
| 571 | ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN); |
| 572 | ath9k_hw_set_interrupts(ah); |
| 573 | } |
| 574 | |
| 575 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 576 | if (status & ATH9K_INT_TIM_TIMER) { |
| 577 | if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle)) |
| 578 | goto chip_reset; |
| 579 | /* Clear RxAbort bit so that we can |
| 580 | * receive frames */ |
| 581 | ath9k_setpower(sc, ATH9K_PM_AWAKE); |
| 582 | spin_lock(&sc->sc_pm_lock); |
| 583 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
| 584 | sc->ps_flags |= PS_WAIT_FOR_BEACON; |
| 585 | spin_unlock(&sc->sc_pm_lock); |
| 586 | } |
| 587 | |
| 588 | chip_reset: |
| 589 | |
| 590 | ath_debug_stat_interrupt(sc, status); |
| 591 | |
| 592 | if (sched) { |
| 593 | /* turn off every interrupt */ |
| 594 | ath9k_hw_kill_interrupts(ah); |
| 595 | tasklet_schedule(&sc->intr_tq); |
| 596 | } |
| 597 | |
| 598 | return IRQ_HANDLED; |
| 599 | |
| 600 | #undef SCHED_INTR |
| 601 | } |
| 602 | |
| 603 | /* |
| 604 | * This function is called when a HW reset cannot be deferred |
| 605 | * and has to be immediate. |
| 606 | */ |
| 607 | int ath_reset(struct ath_softc *sc, struct ath9k_channel *hchan) |
| 608 | { |
| 609 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 610 | int r; |
| 611 | |
| 612 | ath9k_hw_kill_interrupts(sc->sc_ah); |
| 613 | set_bit(ATH_OP_HW_RESET, &common->op_flags); |
| 614 | |
| 615 | ath9k_ps_wakeup(sc); |
| 616 | r = ath_reset_internal(sc, hchan); |
| 617 | ath9k_ps_restore(sc); |
| 618 | |
| 619 | return r; |
| 620 | } |
| 621 | |
| 622 | /* |
| 623 | * When a HW reset can be deferred, it is added to the |
| 624 | * hw_reset_work workqueue, but we set ATH_OP_HW_RESET before |
| 625 | * queueing. |
| 626 | */ |
| 627 | void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type) |
| 628 | { |
| 629 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 630 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 631 | RESET_STAT_INC(sc, type); |
| 632 | #endif |
| 633 | ath9k_hw_kill_interrupts(sc->sc_ah); |
| 634 | set_bit(ATH_OP_HW_RESET, &common->op_flags); |
| 635 | ieee80211_queue_work(sc->hw, &sc->hw_reset_work); |
| 636 | } |
| 637 | |
| 638 | void ath_reset_work(struct work_struct *work) |
| 639 | { |
| 640 | struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work); |
| 641 | |
| 642 | ath9k_ps_wakeup(sc); |
| 643 | ath_reset_internal(sc, NULL); |
| 644 | ath9k_ps_restore(sc); |
| 645 | } |
| 646 | |
| 647 | /**********************/ |
| 648 | /* mac80211 callbacks */ |
| 649 | /**********************/ |
| 650 | |
| 651 | static int ath9k_start(struct ieee80211_hw *hw) |
| 652 | { |
| 653 | struct ath_softc *sc = hw->priv; |
| 654 | struct ath_hw *ah = sc->sc_ah; |
| 655 | struct ath_common *common = ath9k_hw_common(ah); |
| 656 | struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan; |
| 657 | struct ath_chanctx *ctx = sc->cur_chan; |
| 658 | struct ath9k_channel *init_channel; |
| 659 | int r; |
| 660 | |
| 661 | ath_dbg(common, CONFIG, |
| 662 | "Starting driver with initial channel: %d MHz\n", |
| 663 | curchan->center_freq); |
| 664 | |
| 665 | ath9k_ps_wakeup(sc); |
| 666 | mutex_lock(&sc->mutex); |
| 667 | |
| 668 | init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef); |
| 669 | sc->cur_chandef = hw->conf.chandef; |
| 670 | |
| 671 | /* Reset SERDES registers */ |
| 672 | ath9k_hw_configpcipowersave(ah, false); |
| 673 | |
| 674 | /* |
| 675 | * The basic interface to setting the hardware in a good |
| 676 | * state is ``reset''. On return the hardware is known to |
| 677 | * be powered up and with interrupts disabled. This must |
| 678 | * be followed by initialization of the appropriate bits |
| 679 | * and then setup of the interrupt mask. |
| 680 | */ |
| 681 | spin_lock_bh(&sc->sc_pcu_lock); |
| 682 | |
| 683 | atomic_set(&ah->intr_ref_cnt, -1); |
| 684 | |
| 685 | r = ath9k_hw_reset(ah, init_channel, ah->caldata, false); |
| 686 | if (r) { |
| 687 | ath_err(common, |
| 688 | "Unable to reset hardware; reset status %d (freq %u MHz)\n", |
| 689 | r, curchan->center_freq); |
| 690 | ah->reset_power_on = false; |
| 691 | } |
| 692 | |
| 693 | /* Setup our intr mask. */ |
| 694 | ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL | |
| 695 | ATH9K_INT_RXORN | ATH9K_INT_FATAL | |
| 696 | ATH9K_INT_GLOBAL; |
| 697 | |
| 698 | if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) |
| 699 | ah->imask |= ATH9K_INT_RXHP | |
| 700 | ATH9K_INT_RXLP; |
| 701 | else |
| 702 | ah->imask |= ATH9K_INT_RX; |
| 703 | |
| 704 | if (ah->config.hw_hang_checks & HW_BB_WATCHDOG) |
| 705 | ah->imask |= ATH9K_INT_BB_WATCHDOG; |
| 706 | |
| 707 | /* |
| 708 | * Enable GTT interrupts only for AR9003/AR9004 chips |
| 709 | * for now. |
| 710 | */ |
| 711 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 712 | ah->imask |= ATH9K_INT_GTT; |
| 713 | |
| 714 | if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) |
| 715 | ah->imask |= ATH9K_INT_CST; |
| 716 | |
| 717 | ath_mci_enable(sc); |
| 718 | |
| 719 | clear_bit(ATH_OP_INVALID, &common->op_flags); |
| 720 | sc->sc_ah->is_monitoring = false; |
| 721 | |
| 722 | if (!ath_complete_reset(sc, false)) |
| 723 | ah->reset_power_on = false; |
| 724 | |
| 725 | if (ah->led_pin >= 0) { |
| 726 | ath9k_hw_set_gpio(ah, ah->led_pin, |
| 727 | (ah->config.led_active_high) ? 1 : 0); |
| 728 | ath9k_hw_gpio_request_out(ah, ah->led_pin, NULL, |
| 729 | AR_GPIO_OUTPUT_MUX_AS_OUTPUT); |
| 730 | } |
| 731 | |
| 732 | /* |
| 733 | * Reset key cache to sane defaults (all entries cleared) instead of |
| 734 | * semi-random values after suspend/resume. |
| 735 | */ |
| 736 | ath9k_cmn_init_crypto(sc->sc_ah); |
| 737 | |
| 738 | ath9k_hw_reset_tsf(ah); |
| 739 | |
| 740 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 741 | |
| 742 | ath9k_rng_start(sc); |
| 743 | |
| 744 | mutex_unlock(&sc->mutex); |
| 745 | |
| 746 | ath9k_ps_restore(sc); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static void ath9k_tx(struct ieee80211_hw *hw, |
| 752 | struct ieee80211_tx_control *control, |
| 753 | struct sk_buff *skb) |
| 754 | { |
| 755 | struct ath_softc *sc = hw->priv; |
| 756 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 757 | struct ath_tx_control txctl; |
| 758 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
| 759 | unsigned long flags; |
| 760 | |
| 761 | if (sc->ps_enabled) { |
| 762 | /* |
| 763 | * mac80211 does not set PM field for normal data frames, so we |
| 764 | * need to update that based on the current PS mode. |
| 765 | */ |
| 766 | if (ieee80211_is_data(hdr->frame_control) && |
| 767 | !ieee80211_is_nullfunc(hdr->frame_control) && |
| 768 | !ieee80211_has_pm(hdr->frame_control)) { |
| 769 | ath_dbg(common, PS, |
| 770 | "Add PM=1 for a TX frame while in PS mode\n"); |
| 771 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) { |
| 776 | /* |
| 777 | * We are using PS-Poll and mac80211 can request TX while in |
| 778 | * power save mode. Need to wake up hardware for the TX to be |
| 779 | * completed and if needed, also for RX of buffered frames. |
| 780 | */ |
| 781 | ath9k_ps_wakeup(sc); |
| 782 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 783 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) |
| 784 | ath9k_hw_setrxabort(sc->sc_ah, 0); |
| 785 | if (ieee80211_is_pspoll(hdr->frame_control)) { |
| 786 | ath_dbg(common, PS, |
| 787 | "Sending PS-Poll to pick a buffered frame\n"); |
| 788 | sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA; |
| 789 | } else { |
| 790 | ath_dbg(common, PS, "Wake up to complete TX\n"); |
| 791 | sc->ps_flags |= PS_WAIT_FOR_TX_ACK; |
| 792 | } |
| 793 | /* |
| 794 | * The actual restore operation will happen only after |
| 795 | * the ps_flags bit is cleared. We are just dropping |
| 796 | * the ps_usecount here. |
| 797 | */ |
| 798 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 799 | ath9k_ps_restore(sc); |
| 800 | } |
| 801 | |
| 802 | /* |
| 803 | * Cannot tx while the hardware is in full sleep, it first needs a full |
| 804 | * chip reset to recover from that |
| 805 | */ |
| 806 | if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) { |
| 807 | ath_err(common, "TX while HW is in FULL_SLEEP mode\n"); |
| 808 | goto exit; |
| 809 | } |
| 810 | |
| 811 | memset(&txctl, 0, sizeof(struct ath_tx_control)); |
| 812 | txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)]; |
| 813 | txctl.sta = control->sta; |
| 814 | |
| 815 | ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb); |
| 816 | |
| 817 | if (ath_tx_start(hw, skb, &txctl) != 0) { |
| 818 | ath_dbg(common, XMIT, "TX failed\n"); |
| 819 | TX_STAT_INC(sc, txctl.txq->axq_qnum, txfailed); |
| 820 | goto exit; |
| 821 | } |
| 822 | |
| 823 | return; |
| 824 | exit: |
| 825 | ieee80211_free_txskb(hw, skb); |
| 826 | } |
| 827 | |
| 828 | static bool ath9k_txq_list_has_key(struct list_head *txq_list, u32 keyix) |
| 829 | { |
| 830 | struct ath_buf *bf; |
| 831 | struct ieee80211_tx_info *txinfo; |
| 832 | struct ath_frame_info *fi; |
| 833 | |
| 834 | list_for_each_entry(bf, txq_list, list) { |
| 835 | if (bf->bf_state.stale || !bf->bf_mpdu) |
| 836 | continue; |
| 837 | |
| 838 | txinfo = IEEE80211_SKB_CB(bf->bf_mpdu); |
| 839 | fi = (struct ath_frame_info *)&txinfo->status.status_driver_data[0]; |
| 840 | if (fi->keyix == keyix) |
| 841 | return true; |
| 842 | } |
| 843 | |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | static bool ath9k_txq_has_key(struct ath_softc *sc, u32 keyix) |
| 848 | { |
| 849 | struct ath_hw *ah = sc->sc_ah; |
| 850 | int i, j; |
| 851 | struct ath_txq *txq; |
| 852 | bool key_in_use = false; |
| 853 | |
| 854 | for (i = 0; !key_in_use && i < ATH9K_NUM_TX_QUEUES; i++) { |
| 855 | if (!ATH_TXQ_SETUP(sc, i)) |
| 856 | continue; |
| 857 | txq = &sc->tx.txq[i]; |
| 858 | if (!txq->axq_depth) |
| 859 | continue; |
| 860 | if (!ath9k_hw_numtxpending(ah, txq->axq_qnum)) |
| 861 | continue; |
| 862 | |
| 863 | ath_txq_lock(sc, txq); |
| 864 | key_in_use = ath9k_txq_list_has_key(&txq->axq_q, keyix); |
| 865 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) { |
| 866 | int idx = txq->txq_tailidx; |
| 867 | |
| 868 | for (j = 0; !key_in_use && |
| 869 | !list_empty(&txq->txq_fifo[idx]) && |
| 870 | j < ATH_TXFIFO_DEPTH; j++) { |
| 871 | key_in_use = ath9k_txq_list_has_key( |
| 872 | &txq->txq_fifo[idx], keyix); |
| 873 | INCR(idx, ATH_TXFIFO_DEPTH); |
| 874 | } |
| 875 | } |
| 876 | ath_txq_unlock(sc, txq); |
| 877 | } |
| 878 | |
| 879 | return key_in_use; |
| 880 | } |
| 881 | |
| 882 | static void ath9k_pending_key_del(struct ath_softc *sc, u8 keyix) |
| 883 | { |
| 884 | struct ath_hw *ah = sc->sc_ah; |
| 885 | struct ath_common *common = ath9k_hw_common(ah); |
| 886 | |
| 887 | if (!test_bit(keyix, ah->pending_del_keymap) || |
| 888 | ath9k_txq_has_key(sc, keyix)) |
| 889 | return; |
| 890 | |
| 891 | /* No more TXQ frames point to this key cache entry, so delete it. */ |
| 892 | clear_bit(keyix, ah->pending_del_keymap); |
| 893 | ath_key_delete(common, keyix); |
| 894 | } |
| 895 | |
| 896 | static void ath9k_stop(struct ieee80211_hw *hw) |
| 897 | { |
| 898 | struct ath_softc *sc = hw->priv; |
| 899 | struct ath_hw *ah = sc->sc_ah; |
| 900 | struct ath_common *common = ath9k_hw_common(ah); |
| 901 | bool prev_idle; |
| 902 | int i; |
| 903 | |
| 904 | ath9k_deinit_channel_context(sc); |
| 905 | |
| 906 | mutex_lock(&sc->mutex); |
| 907 | |
| 908 | ath9k_rng_stop(sc); |
| 909 | |
| 910 | ath_cancel_work(sc); |
| 911 | |
| 912 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) { |
| 913 | ath_dbg(common, ANY, "Device not present\n"); |
| 914 | mutex_unlock(&sc->mutex); |
| 915 | return; |
| 916 | } |
| 917 | |
| 918 | /* Ensure HW is awake when we try to shut it down. */ |
| 919 | ath9k_ps_wakeup(sc); |
| 920 | |
| 921 | spin_lock_bh(&sc->sc_pcu_lock); |
| 922 | |
| 923 | /* prevent tasklets to enable interrupts once we disable them */ |
| 924 | ah->imask &= ~ATH9K_INT_GLOBAL; |
| 925 | |
| 926 | /* make sure h/w will not generate any interrupt |
| 927 | * before setting the invalid flag. */ |
| 928 | ath9k_hw_disable_interrupts(ah); |
| 929 | |
| 930 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 931 | |
| 932 | /* we can now sync irq and kill any running tasklets, since we already |
| 933 | * disabled interrupts and not holding a spin lock */ |
| 934 | synchronize_irq(sc->irq); |
| 935 | tasklet_kill(&sc->intr_tq); |
| 936 | tasklet_kill(&sc->bcon_tasklet); |
| 937 | |
| 938 | prev_idle = sc->ps_idle; |
| 939 | sc->ps_idle = true; |
| 940 | |
| 941 | spin_lock_bh(&sc->sc_pcu_lock); |
| 942 | |
| 943 | if (ah->led_pin >= 0) { |
| 944 | ath9k_hw_set_gpio(ah, ah->led_pin, |
| 945 | (ah->config.led_active_high) ? 0 : 1); |
| 946 | ath9k_hw_gpio_request_in(ah, ah->led_pin, NULL); |
| 947 | } |
| 948 | |
| 949 | ath_prepare_reset(sc); |
| 950 | |
| 951 | if (sc->rx.frag) { |
| 952 | dev_kfree_skb_any(sc->rx.frag); |
| 953 | sc->rx.frag = NULL; |
| 954 | } |
| 955 | |
| 956 | if (!ah->curchan) |
| 957 | ah->curchan = ath9k_cmn_get_channel(hw, ah, |
| 958 | &sc->cur_chan->chandef); |
| 959 | |
| 960 | ath9k_hw_reset(ah, ah->curchan, ah->caldata, false); |
| 961 | |
| 962 | set_bit(ATH_OP_INVALID, &common->op_flags); |
| 963 | |
| 964 | ath9k_hw_phy_disable(ah); |
| 965 | |
| 966 | ath9k_hw_configpcipowersave(ah, true); |
| 967 | |
| 968 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 969 | |
| 970 | for (i = 0; i < ATH_KEYMAX; i++) |
| 971 | ath9k_pending_key_del(sc, i); |
| 972 | |
| 973 | /* Clear key cache entries explicitly to get rid of any potentially |
| 974 | * remaining keys. |
| 975 | */ |
| 976 | ath9k_cmn_init_crypto(sc->sc_ah); |
| 977 | |
| 978 | ath9k_ps_restore(sc); |
| 979 | |
| 980 | sc->ps_idle = prev_idle; |
| 981 | |
| 982 | mutex_unlock(&sc->mutex); |
| 983 | |
| 984 | ath_dbg(common, CONFIG, "Driver halt\n"); |
| 985 | } |
| 986 | |
| 987 | static bool ath9k_uses_beacons(int type) |
| 988 | { |
| 989 | switch (type) { |
| 990 | case NL80211_IFTYPE_AP: |
| 991 | case NL80211_IFTYPE_ADHOC: |
| 992 | case NL80211_IFTYPE_MESH_POINT: |
| 993 | return true; |
| 994 | default: |
| 995 | return false; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | static void ath9k_vif_iter_set_beacon(struct ath9k_vif_iter_data *iter_data, |
| 1000 | struct ieee80211_vif *vif) |
| 1001 | { |
| 1002 | /* Use the first (configured) interface, but prefering AP interfaces. */ |
| 1003 | if (!iter_data->primary_beacon_vif) { |
| 1004 | iter_data->primary_beacon_vif = vif; |
| 1005 | } else { |
| 1006 | if (iter_data->primary_beacon_vif->type != NL80211_IFTYPE_AP && |
| 1007 | vif->type == NL80211_IFTYPE_AP) |
| 1008 | iter_data->primary_beacon_vif = vif; |
| 1009 | } |
| 1010 | |
| 1011 | iter_data->beacons = true; |
| 1012 | iter_data->nbcnvifs += 1; |
| 1013 | } |
| 1014 | |
| 1015 | static void ath9k_vif_iter(struct ath9k_vif_iter_data *iter_data, |
| 1016 | u8 *mac, struct ieee80211_vif *vif) |
| 1017 | { |
| 1018 | struct ath_vif *avp = (struct ath_vif *)vif->drv_priv; |
| 1019 | int i; |
| 1020 | |
| 1021 | if (iter_data->has_hw_macaddr) { |
| 1022 | for (i = 0; i < ETH_ALEN; i++) |
| 1023 | iter_data->mask[i] &= |
| 1024 | ~(iter_data->hw_macaddr[i] ^ mac[i]); |
| 1025 | } else { |
| 1026 | memcpy(iter_data->hw_macaddr, mac, ETH_ALEN); |
| 1027 | iter_data->has_hw_macaddr = true; |
| 1028 | } |
| 1029 | |
| 1030 | if (!vif->bss_conf.use_short_slot) |
| 1031 | iter_data->slottime = 20; |
| 1032 | |
| 1033 | switch (vif->type) { |
| 1034 | case NL80211_IFTYPE_AP: |
| 1035 | iter_data->naps++; |
| 1036 | if (vif->bss_conf.enable_beacon) |
| 1037 | ath9k_vif_iter_set_beacon(iter_data, vif); |
| 1038 | break; |
| 1039 | case NL80211_IFTYPE_STATION: |
| 1040 | iter_data->nstations++; |
| 1041 | if (avp->assoc && !iter_data->primary_sta) |
| 1042 | iter_data->primary_sta = vif; |
| 1043 | break; |
| 1044 | case NL80211_IFTYPE_OCB: |
| 1045 | iter_data->nocbs++; |
| 1046 | break; |
| 1047 | case NL80211_IFTYPE_ADHOC: |
| 1048 | iter_data->nadhocs++; |
| 1049 | if (vif->bss_conf.enable_beacon) |
| 1050 | ath9k_vif_iter_set_beacon(iter_data, vif); |
| 1051 | break; |
| 1052 | case NL80211_IFTYPE_MESH_POINT: |
| 1053 | iter_data->nmeshes++; |
| 1054 | if (vif->bss_conf.enable_beacon) |
| 1055 | ath9k_vif_iter_set_beacon(iter_data, vif); |
| 1056 | break; |
| 1057 | case NL80211_IFTYPE_WDS: |
| 1058 | iter_data->nwds++; |
| 1059 | break; |
| 1060 | default: |
| 1061 | break; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | static void ath9k_update_bssid_mask(struct ath_softc *sc, |
| 1066 | struct ath_chanctx *ctx, |
| 1067 | struct ath9k_vif_iter_data *iter_data) |
| 1068 | { |
| 1069 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1070 | struct ath_vif *avp; |
| 1071 | int i; |
| 1072 | |
| 1073 | if (!ath9k_is_chanctx_enabled()) |
| 1074 | return; |
| 1075 | |
| 1076 | list_for_each_entry(avp, &ctx->vifs, list) { |
| 1077 | if (ctx->nvifs_assigned != 1) |
| 1078 | continue; |
| 1079 | |
| 1080 | if (!iter_data->has_hw_macaddr) |
| 1081 | continue; |
| 1082 | |
| 1083 | ether_addr_copy(common->curbssid, avp->bssid); |
| 1084 | |
| 1085 | /* perm_addr will be used as the p2p device address. */ |
| 1086 | for (i = 0; i < ETH_ALEN; i++) |
| 1087 | iter_data->mask[i] &= |
| 1088 | ~(iter_data->hw_macaddr[i] ^ |
| 1089 | sc->hw->wiphy->perm_addr[i]); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | /* Called with sc->mutex held. */ |
| 1094 | void ath9k_calculate_iter_data(struct ath_softc *sc, |
| 1095 | struct ath_chanctx *ctx, |
| 1096 | struct ath9k_vif_iter_data *iter_data) |
| 1097 | { |
| 1098 | struct ath_vif *avp; |
| 1099 | |
| 1100 | /* |
| 1101 | * The hardware will use primary station addr together with the |
| 1102 | * BSSID mask when matching addresses. |
| 1103 | */ |
| 1104 | memset(iter_data, 0, sizeof(*iter_data)); |
| 1105 | eth_broadcast_addr(iter_data->mask); |
| 1106 | iter_data->slottime = 9; |
| 1107 | |
| 1108 | list_for_each_entry(avp, &ctx->vifs, list) |
| 1109 | ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif); |
| 1110 | |
| 1111 | ath9k_update_bssid_mask(sc, ctx, iter_data); |
| 1112 | } |
| 1113 | |
| 1114 | static void ath9k_set_assoc_state(struct ath_softc *sc, |
| 1115 | struct ieee80211_vif *vif, bool changed) |
| 1116 | { |
| 1117 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1118 | struct ath_vif *avp = (struct ath_vif *)vif->drv_priv; |
| 1119 | unsigned long flags; |
| 1120 | |
| 1121 | set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags); |
| 1122 | |
| 1123 | ether_addr_copy(common->curbssid, avp->bssid); |
| 1124 | common->curaid = avp->aid; |
| 1125 | ath9k_hw_write_associd(sc->sc_ah); |
| 1126 | |
| 1127 | if (changed) { |
| 1128 | common->last_rssi = ATH_RSSI_DUMMY_MARKER; |
| 1129 | sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; |
| 1130 | |
| 1131 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 1132 | sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; |
| 1133 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 1134 | } |
| 1135 | |
| 1136 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 1137 | ath9k_mci_update_wlan_channels(sc, false); |
| 1138 | |
| 1139 | ath_dbg(common, CONFIG, |
| 1140 | "Primary Station interface: %pM, BSSID: %pM\n", |
| 1141 | vif->addr, common->curbssid); |
| 1142 | } |
| 1143 | |
| 1144 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 1145 | static void ath9k_set_offchannel_state(struct ath_softc *sc) |
| 1146 | { |
| 1147 | struct ath_hw *ah = sc->sc_ah; |
| 1148 | struct ath_common *common = ath9k_hw_common(ah); |
| 1149 | struct ieee80211_vif *vif = NULL; |
| 1150 | |
| 1151 | ath9k_ps_wakeup(sc); |
| 1152 | |
| 1153 | if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START) |
| 1154 | vif = sc->offchannel.scan_vif; |
| 1155 | else |
| 1156 | vif = sc->offchannel.roc_vif; |
| 1157 | |
| 1158 | if (WARN_ON(!vif)) |
| 1159 | goto exit; |
| 1160 | |
| 1161 | eth_zero_addr(common->curbssid); |
| 1162 | eth_broadcast_addr(common->bssidmask); |
| 1163 | memcpy(common->macaddr, vif->addr, ETH_ALEN); |
| 1164 | common->curaid = 0; |
| 1165 | ah->opmode = vif->type; |
| 1166 | ah->imask &= ~ATH9K_INT_SWBA; |
| 1167 | ah->imask &= ~ATH9K_INT_TSFOOR; |
| 1168 | ah->slottime = 9; |
| 1169 | |
| 1170 | ath_hw_setbssidmask(common); |
| 1171 | ath9k_hw_setopmode(ah); |
| 1172 | ath9k_hw_write_associd(sc->sc_ah); |
| 1173 | ath9k_hw_set_interrupts(ah); |
| 1174 | ath9k_hw_init_global_settings(ah); |
| 1175 | |
| 1176 | exit: |
| 1177 | ath9k_ps_restore(sc); |
| 1178 | } |
| 1179 | #endif |
| 1180 | |
| 1181 | /* Called with sc->mutex held. */ |
| 1182 | void ath9k_calculate_summary_state(struct ath_softc *sc, |
| 1183 | struct ath_chanctx *ctx) |
| 1184 | { |
| 1185 | struct ath_hw *ah = sc->sc_ah; |
| 1186 | struct ath_common *common = ath9k_hw_common(ah); |
| 1187 | struct ath9k_vif_iter_data iter_data; |
| 1188 | |
| 1189 | ath_chanctx_check_active(sc, ctx); |
| 1190 | |
| 1191 | if (ctx != sc->cur_chan) |
| 1192 | return; |
| 1193 | |
| 1194 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 1195 | if (ctx == &sc->offchannel.chan) |
| 1196 | return ath9k_set_offchannel_state(sc); |
| 1197 | #endif |
| 1198 | |
| 1199 | ath9k_ps_wakeup(sc); |
| 1200 | ath9k_calculate_iter_data(sc, ctx, &iter_data); |
| 1201 | |
| 1202 | if (iter_data.has_hw_macaddr) |
| 1203 | memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN); |
| 1204 | |
| 1205 | memcpy(common->bssidmask, iter_data.mask, ETH_ALEN); |
| 1206 | ath_hw_setbssidmask(common); |
| 1207 | |
| 1208 | if (iter_data.naps > 0) { |
| 1209 | ath9k_hw_set_tsfadjust(ah, true); |
| 1210 | ah->opmode = NL80211_IFTYPE_AP; |
| 1211 | } else { |
| 1212 | ath9k_hw_set_tsfadjust(ah, false); |
| 1213 | if (iter_data.beacons) |
| 1214 | ath9k_beacon_ensure_primary_slot(sc); |
| 1215 | |
| 1216 | if (iter_data.nmeshes) |
| 1217 | ah->opmode = NL80211_IFTYPE_MESH_POINT; |
| 1218 | else if (iter_data.nocbs) |
| 1219 | ah->opmode = NL80211_IFTYPE_OCB; |
| 1220 | else if (iter_data.nwds) |
| 1221 | ah->opmode = NL80211_IFTYPE_AP; |
| 1222 | else if (iter_data.nadhocs) |
| 1223 | ah->opmode = NL80211_IFTYPE_ADHOC; |
| 1224 | else |
| 1225 | ah->opmode = NL80211_IFTYPE_STATION; |
| 1226 | } |
| 1227 | |
| 1228 | ath9k_hw_setopmode(ah); |
| 1229 | |
| 1230 | ctx->switch_after_beacon = false; |
| 1231 | if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) |
| 1232 | ah->imask |= ATH9K_INT_TSFOOR; |
| 1233 | else { |
| 1234 | ah->imask &= ~ATH9K_INT_TSFOOR; |
| 1235 | if (iter_data.naps == 1 && iter_data.beacons) |
| 1236 | ctx->switch_after_beacon = true; |
| 1237 | } |
| 1238 | |
| 1239 | if (ah->opmode == NL80211_IFTYPE_STATION) { |
| 1240 | bool changed = (iter_data.primary_sta != ctx->primary_sta); |
| 1241 | |
| 1242 | if (iter_data.primary_sta) { |
| 1243 | iter_data.primary_beacon_vif = iter_data.primary_sta; |
| 1244 | iter_data.beacons = true; |
| 1245 | ath9k_set_assoc_state(sc, iter_data.primary_sta, |
| 1246 | changed); |
| 1247 | ctx->primary_sta = iter_data.primary_sta; |
| 1248 | } else { |
| 1249 | ctx->primary_sta = NULL; |
| 1250 | eth_zero_addr(common->curbssid); |
| 1251 | common->curaid = 0; |
| 1252 | ath9k_hw_write_associd(sc->sc_ah); |
| 1253 | if (ath9k_hw_mci_is_enabled(sc->sc_ah)) |
| 1254 | ath9k_mci_update_wlan_channels(sc, true); |
| 1255 | } |
| 1256 | } |
| 1257 | sc->nbcnvifs = iter_data.nbcnvifs; |
| 1258 | ath9k_beacon_config(sc, iter_data.primary_beacon_vif, |
| 1259 | iter_data.beacons); |
| 1260 | ath9k_hw_set_interrupts(ah); |
| 1261 | |
| 1262 | if (ah->slottime != iter_data.slottime) { |
| 1263 | ah->slottime = iter_data.slottime; |
| 1264 | ath9k_hw_init_global_settings(ah); |
| 1265 | } |
| 1266 | |
| 1267 | if (iter_data.primary_sta) |
| 1268 | set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags); |
| 1269 | else |
| 1270 | clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags); |
| 1271 | |
| 1272 | ath_dbg(common, CONFIG, |
| 1273 | "macaddr: %pM, bssid: %pM, bssidmask: %pM\n", |
| 1274 | common->macaddr, common->curbssid, common->bssidmask); |
| 1275 | |
| 1276 | ath9k_ps_restore(sc); |
| 1277 | } |
| 1278 | |
| 1279 | static void ath9k_tpc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 1280 | { |
| 1281 | int *power = data; |
| 1282 | |
| 1283 | if (*power < vif->bss_conf.txpower) |
| 1284 | *power = vif->bss_conf.txpower; |
| 1285 | } |
| 1286 | |
| 1287 | /* Called with sc->mutex held. */ |
| 1288 | void ath9k_set_txpower(struct ath_softc *sc, struct ieee80211_vif *vif) |
| 1289 | { |
| 1290 | int power; |
| 1291 | struct ath_hw *ah = sc->sc_ah; |
| 1292 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
| 1293 | |
| 1294 | ath9k_ps_wakeup(sc); |
| 1295 | if (ah->tpc_enabled) { |
| 1296 | power = (vif) ? vif->bss_conf.txpower : -1; |
| 1297 | ieee80211_iterate_active_interfaces_atomic( |
| 1298 | sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, |
| 1299 | ath9k_tpc_vif_iter, &power); |
| 1300 | if (power == -1) |
| 1301 | power = sc->hw->conf.power_level; |
| 1302 | } else { |
| 1303 | power = sc->hw->conf.power_level; |
| 1304 | } |
| 1305 | sc->cur_chan->txpower = 2 * power; |
| 1306 | ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false); |
| 1307 | sc->cur_chan->cur_txpower = reg->max_power_level; |
| 1308 | ath9k_ps_restore(sc); |
| 1309 | } |
| 1310 | |
| 1311 | static void ath9k_assign_hw_queues(struct ieee80211_hw *hw, |
| 1312 | struct ieee80211_vif *vif) |
| 1313 | { |
| 1314 | int i; |
| 1315 | |
| 1316 | if (!ath9k_is_chanctx_enabled()) |
| 1317 | return; |
| 1318 | |
| 1319 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 1320 | vif->hw_queue[i] = i; |
| 1321 | |
| 1322 | if (vif->type == NL80211_IFTYPE_AP || |
| 1323 | vif->type == NL80211_IFTYPE_MESH_POINT) |
| 1324 | vif->cab_queue = hw->queues - 2; |
| 1325 | else |
| 1326 | vif->cab_queue = IEEE80211_INVAL_HW_QUEUE; |
| 1327 | } |
| 1328 | |
| 1329 | static int ath9k_add_interface(struct ieee80211_hw *hw, |
| 1330 | struct ieee80211_vif *vif) |
| 1331 | { |
| 1332 | struct ath_softc *sc = hw->priv; |
| 1333 | struct ath_hw *ah = sc->sc_ah; |
| 1334 | struct ath_common *common = ath9k_hw_common(ah); |
| 1335 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1336 | struct ath_node *an = &avp->mcast_node; |
| 1337 | |
| 1338 | mutex_lock(&sc->mutex); |
| 1339 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) { |
| 1340 | if (sc->cur_chan->nvifs >= 1) { |
| 1341 | mutex_unlock(&sc->mutex); |
| 1342 | return -EOPNOTSUPP; |
| 1343 | } |
| 1344 | sc->tx99_vif = vif; |
| 1345 | } |
| 1346 | |
| 1347 | ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type); |
| 1348 | sc->cur_chan->nvifs++; |
| 1349 | |
| 1350 | if (vif->type == NL80211_IFTYPE_STATION && ath9k_is_chanctx_enabled()) |
| 1351 | vif->driver_flags |= IEEE80211_VIF_GET_NOA_UPDATE; |
| 1352 | |
| 1353 | if (ath9k_uses_beacons(vif->type)) |
| 1354 | ath9k_beacon_assign_slot(sc, vif); |
| 1355 | |
| 1356 | avp->vif = vif; |
| 1357 | if (!ath9k_is_chanctx_enabled()) { |
| 1358 | avp->chanctx = sc->cur_chan; |
| 1359 | list_add_tail(&avp->list, &avp->chanctx->vifs); |
| 1360 | } |
| 1361 | |
| 1362 | ath9k_calculate_summary_state(sc, avp->chanctx); |
| 1363 | |
| 1364 | ath9k_assign_hw_queues(hw, vif); |
| 1365 | |
| 1366 | ath9k_set_txpower(sc, vif); |
| 1367 | |
| 1368 | an->sc = sc; |
| 1369 | an->sta = NULL; |
| 1370 | an->vif = vif; |
| 1371 | an->no_ps_filter = true; |
| 1372 | ath_tx_node_init(sc, an); |
| 1373 | |
| 1374 | mutex_unlock(&sc->mutex); |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | static int ath9k_change_interface(struct ieee80211_hw *hw, |
| 1379 | struct ieee80211_vif *vif, |
| 1380 | enum nl80211_iftype new_type, |
| 1381 | bool p2p) |
| 1382 | { |
| 1383 | struct ath_softc *sc = hw->priv; |
| 1384 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1385 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1386 | |
| 1387 | mutex_lock(&sc->mutex); |
| 1388 | |
| 1389 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) { |
| 1390 | mutex_unlock(&sc->mutex); |
| 1391 | return -EOPNOTSUPP; |
| 1392 | } |
| 1393 | |
| 1394 | ath_dbg(common, CONFIG, "Change Interface\n"); |
| 1395 | |
| 1396 | if (ath9k_uses_beacons(vif->type)) |
| 1397 | ath9k_beacon_remove_slot(sc, vif); |
| 1398 | |
| 1399 | vif->type = new_type; |
| 1400 | vif->p2p = p2p; |
| 1401 | |
| 1402 | if (ath9k_uses_beacons(vif->type)) |
| 1403 | ath9k_beacon_assign_slot(sc, vif); |
| 1404 | |
| 1405 | ath9k_assign_hw_queues(hw, vif); |
| 1406 | ath9k_calculate_summary_state(sc, avp->chanctx); |
| 1407 | |
| 1408 | ath9k_set_txpower(sc, vif); |
| 1409 | |
| 1410 | mutex_unlock(&sc->mutex); |
| 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | static void ath9k_remove_interface(struct ieee80211_hw *hw, |
| 1415 | struct ieee80211_vif *vif) |
| 1416 | { |
| 1417 | struct ath_softc *sc = hw->priv; |
| 1418 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1419 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1420 | |
| 1421 | ath_dbg(common, CONFIG, "Detach Interface\n"); |
| 1422 | |
| 1423 | mutex_lock(&sc->mutex); |
| 1424 | |
| 1425 | ath9k_p2p_remove_vif(sc, vif); |
| 1426 | |
| 1427 | sc->cur_chan->nvifs--; |
| 1428 | sc->tx99_vif = NULL; |
| 1429 | if (!ath9k_is_chanctx_enabled()) |
| 1430 | list_del(&avp->list); |
| 1431 | |
| 1432 | if (ath9k_uses_beacons(vif->type)) |
| 1433 | ath9k_beacon_remove_slot(sc, vif); |
| 1434 | |
| 1435 | ath_tx_node_cleanup(sc, &avp->mcast_node); |
| 1436 | |
| 1437 | ath9k_calculate_summary_state(sc, avp->chanctx); |
| 1438 | |
| 1439 | ath9k_set_txpower(sc, NULL); |
| 1440 | |
| 1441 | mutex_unlock(&sc->mutex); |
| 1442 | } |
| 1443 | |
| 1444 | static void ath9k_enable_ps(struct ath_softc *sc) |
| 1445 | { |
| 1446 | struct ath_hw *ah = sc->sc_ah; |
| 1447 | struct ath_common *common = ath9k_hw_common(ah); |
| 1448 | |
| 1449 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) |
| 1450 | return; |
| 1451 | |
| 1452 | sc->ps_enabled = true; |
| 1453 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1454 | if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) { |
| 1455 | ah->imask |= ATH9K_INT_TIM_TIMER; |
| 1456 | ath9k_hw_set_interrupts(ah); |
| 1457 | } |
| 1458 | ath9k_hw_setrxabort(ah, 1); |
| 1459 | } |
| 1460 | ath_dbg(common, PS, "PowerSave enabled\n"); |
| 1461 | } |
| 1462 | |
| 1463 | static void ath9k_disable_ps(struct ath_softc *sc) |
| 1464 | { |
| 1465 | struct ath_hw *ah = sc->sc_ah; |
| 1466 | struct ath_common *common = ath9k_hw_common(ah); |
| 1467 | |
| 1468 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) |
| 1469 | return; |
| 1470 | |
| 1471 | sc->ps_enabled = false; |
| 1472 | ath9k_hw_setpower(ah, ATH9K_PM_AWAKE); |
| 1473 | if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { |
| 1474 | ath9k_hw_setrxabort(ah, 0); |
| 1475 | sc->ps_flags &= ~(PS_WAIT_FOR_BEACON | |
| 1476 | PS_WAIT_FOR_CAB | |
| 1477 | PS_WAIT_FOR_PSPOLL_DATA | |
| 1478 | PS_WAIT_FOR_TX_ACK); |
| 1479 | if (ah->imask & ATH9K_INT_TIM_TIMER) { |
| 1480 | ah->imask &= ~ATH9K_INT_TIM_TIMER; |
| 1481 | ath9k_hw_set_interrupts(ah); |
| 1482 | } |
| 1483 | } |
| 1484 | ath_dbg(common, PS, "PowerSave disabled\n"); |
| 1485 | } |
| 1486 | |
| 1487 | static int ath9k_config(struct ieee80211_hw *hw, u32 changed) |
| 1488 | { |
| 1489 | struct ath_softc *sc = hw->priv; |
| 1490 | struct ath_hw *ah = sc->sc_ah; |
| 1491 | struct ath_common *common = ath9k_hw_common(ah); |
| 1492 | struct ieee80211_conf *conf = &hw->conf; |
| 1493 | struct ath_chanctx *ctx = sc->cur_chan; |
| 1494 | |
| 1495 | ath9k_ps_wakeup(sc); |
| 1496 | mutex_lock(&sc->mutex); |
| 1497 | |
| 1498 | if (changed & IEEE80211_CONF_CHANGE_IDLE) { |
| 1499 | sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
| 1500 | if (sc->ps_idle) { |
| 1501 | ath_cancel_work(sc); |
| 1502 | ath9k_stop_btcoex(sc); |
| 1503 | } else { |
| 1504 | ath9k_start_btcoex(sc); |
| 1505 | /* |
| 1506 | * The chip needs a reset to properly wake up from |
| 1507 | * full sleep |
| 1508 | */ |
| 1509 | ath_chanctx_set_channel(sc, ctx, &ctx->chandef); |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | * We just prepare to enable PS. We have to wait until our AP has |
| 1515 | * ACK'd our null data frame to disable RX otherwise we'll ignore |
| 1516 | * those ACKs and end up retransmitting the same null data frames. |
| 1517 | * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode. |
| 1518 | */ |
| 1519 | if (changed & IEEE80211_CONF_CHANGE_PS) { |
| 1520 | unsigned long flags; |
| 1521 | spin_lock_irqsave(&sc->sc_pm_lock, flags); |
| 1522 | if (conf->flags & IEEE80211_CONF_PS) |
| 1523 | ath9k_enable_ps(sc); |
| 1524 | else |
| 1525 | ath9k_disable_ps(sc); |
| 1526 | spin_unlock_irqrestore(&sc->sc_pm_lock, flags); |
| 1527 | } |
| 1528 | |
| 1529 | if (changed & IEEE80211_CONF_CHANGE_MONITOR) { |
| 1530 | if (conf->flags & IEEE80211_CONF_MONITOR) { |
| 1531 | ath_dbg(common, CONFIG, "Monitor mode is enabled\n"); |
| 1532 | sc->sc_ah->is_monitoring = true; |
| 1533 | } else { |
| 1534 | ath_dbg(common, CONFIG, "Monitor mode is disabled\n"); |
| 1535 | sc->sc_ah->is_monitoring = false; |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | if (!ath9k_is_chanctx_enabled() && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) { |
| 1540 | ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL); |
| 1541 | ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef); |
| 1542 | } |
| 1543 | |
| 1544 | if (changed & IEEE80211_CONF_CHANGE_POWER) |
| 1545 | ath9k_set_txpower(sc, NULL); |
| 1546 | |
| 1547 | mutex_unlock(&sc->mutex); |
| 1548 | ath9k_ps_restore(sc); |
| 1549 | |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
| 1553 | #define SUPPORTED_FILTERS \ |
| 1554 | (FIF_ALLMULTI | \ |
| 1555 | FIF_CONTROL | \ |
| 1556 | FIF_PSPOLL | \ |
| 1557 | FIF_OTHER_BSS | \ |
| 1558 | FIF_BCN_PRBRESP_PROMISC | \ |
| 1559 | FIF_PROBE_REQ | \ |
| 1560 | FIF_FCSFAIL) |
| 1561 | |
| 1562 | /* FIXME: sc->sc_full_reset ? */ |
| 1563 | static void ath9k_configure_filter(struct ieee80211_hw *hw, |
| 1564 | unsigned int changed_flags, |
| 1565 | unsigned int *total_flags, |
| 1566 | u64 multicast) |
| 1567 | { |
| 1568 | struct ath_softc *sc = hw->priv; |
| 1569 | struct ath_chanctx *ctx; |
| 1570 | u32 rfilt; |
| 1571 | |
| 1572 | changed_flags &= SUPPORTED_FILTERS; |
| 1573 | *total_flags &= SUPPORTED_FILTERS; |
| 1574 | |
| 1575 | spin_lock_bh(&sc->chan_lock); |
| 1576 | ath_for_each_chanctx(sc, ctx) |
| 1577 | ctx->rxfilter = *total_flags; |
| 1578 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 1579 | sc->offchannel.chan.rxfilter = *total_flags; |
| 1580 | #endif |
| 1581 | spin_unlock_bh(&sc->chan_lock); |
| 1582 | |
| 1583 | ath9k_ps_wakeup(sc); |
| 1584 | rfilt = ath_calcrxfilter(sc); |
| 1585 | ath9k_hw_setrxfilter(sc->sc_ah, rfilt); |
| 1586 | ath9k_ps_restore(sc); |
| 1587 | |
| 1588 | ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n", |
| 1589 | rfilt); |
| 1590 | } |
| 1591 | |
| 1592 | static int ath9k_sta_add(struct ieee80211_hw *hw, |
| 1593 | struct ieee80211_vif *vif, |
| 1594 | struct ieee80211_sta *sta) |
| 1595 | { |
| 1596 | struct ath_softc *sc = hw->priv; |
| 1597 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1598 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1599 | struct ieee80211_key_conf ps_key = { }; |
| 1600 | int key; |
| 1601 | |
| 1602 | ath_node_attach(sc, sta, vif); |
| 1603 | |
| 1604 | if (vif->type != NL80211_IFTYPE_AP && |
| 1605 | vif->type != NL80211_IFTYPE_AP_VLAN) |
| 1606 | return 0; |
| 1607 | |
| 1608 | key = ath_key_config(common, vif, sta, &ps_key); |
| 1609 | if (key > 0) { |
| 1610 | an->ps_key = key; |
| 1611 | an->key_idx[0] = key; |
| 1612 | } |
| 1613 | |
| 1614 | return 0; |
| 1615 | } |
| 1616 | |
| 1617 | static void ath9k_del_ps_key(struct ath_softc *sc, |
| 1618 | struct ieee80211_vif *vif, |
| 1619 | struct ieee80211_sta *sta) |
| 1620 | { |
| 1621 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1622 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1623 | |
| 1624 | if (!an->ps_key) |
| 1625 | return; |
| 1626 | |
| 1627 | ath_key_delete(common, an->ps_key); |
| 1628 | an->ps_key = 0; |
| 1629 | an->key_idx[0] = 0; |
| 1630 | } |
| 1631 | |
| 1632 | static int ath9k_sta_remove(struct ieee80211_hw *hw, |
| 1633 | struct ieee80211_vif *vif, |
| 1634 | struct ieee80211_sta *sta) |
| 1635 | { |
| 1636 | struct ath_softc *sc = hw->priv; |
| 1637 | |
| 1638 | ath9k_del_ps_key(sc, vif, sta); |
| 1639 | ath_node_detach(sc, sta); |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | static int ath9k_sta_state(struct ieee80211_hw *hw, |
| 1645 | struct ieee80211_vif *vif, |
| 1646 | struct ieee80211_sta *sta, |
| 1647 | enum ieee80211_sta_state old_state, |
| 1648 | enum ieee80211_sta_state new_state) |
| 1649 | { |
| 1650 | struct ath_softc *sc = hw->priv; |
| 1651 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1652 | int ret = 0; |
| 1653 | |
| 1654 | if (old_state == IEEE80211_STA_NOTEXIST && |
| 1655 | new_state == IEEE80211_STA_NONE) { |
| 1656 | ret = ath9k_sta_add(hw, vif, sta); |
| 1657 | ath_dbg(common, CONFIG, |
| 1658 | "Add station: %pM\n", sta->addr); |
| 1659 | } else if (old_state == IEEE80211_STA_NONE && |
| 1660 | new_state == IEEE80211_STA_NOTEXIST) { |
| 1661 | ret = ath9k_sta_remove(hw, vif, sta); |
| 1662 | ath_dbg(common, CONFIG, |
| 1663 | "Remove station: %pM\n", sta->addr); |
| 1664 | } |
| 1665 | |
| 1666 | if (ath9k_is_chanctx_enabled()) { |
| 1667 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1668 | if (old_state == IEEE80211_STA_ASSOC && |
| 1669 | new_state == IEEE80211_STA_AUTHORIZED) |
| 1670 | ath_chanctx_event(sc, vif, |
| 1671 | ATH_CHANCTX_EVENT_AUTHORIZED); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | return ret; |
| 1676 | } |
| 1677 | |
| 1678 | static void ath9k_sta_set_tx_filter(struct ath_hw *ah, |
| 1679 | struct ath_node *an, |
| 1680 | bool set) |
| 1681 | { |
| 1682 | int i; |
| 1683 | |
| 1684 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1685 | if (!an->key_idx[i]) |
| 1686 | continue; |
| 1687 | ath9k_hw_set_tx_filter(ah, an->key_idx[i], set); |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | static void ath9k_sta_notify(struct ieee80211_hw *hw, |
| 1692 | struct ieee80211_vif *vif, |
| 1693 | enum sta_notify_cmd cmd, |
| 1694 | struct ieee80211_sta *sta) |
| 1695 | { |
| 1696 | struct ath_softc *sc = hw->priv; |
| 1697 | struct ath_node *an = (struct ath_node *) sta->drv_priv; |
| 1698 | |
| 1699 | switch (cmd) { |
| 1700 | case STA_NOTIFY_SLEEP: |
| 1701 | an->sleeping = true; |
| 1702 | ath_tx_aggr_sleep(sta, sc, an); |
| 1703 | ath9k_sta_set_tx_filter(sc->sc_ah, an, true); |
| 1704 | break; |
| 1705 | case STA_NOTIFY_AWAKE: |
| 1706 | ath9k_sta_set_tx_filter(sc->sc_ah, an, false); |
| 1707 | an->sleeping = false; |
| 1708 | ath_tx_aggr_wakeup(sc, an); |
| 1709 | break; |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | static int ath9k_conf_tx(struct ieee80211_hw *hw, |
| 1714 | struct ieee80211_vif *vif, u16 queue, |
| 1715 | const struct ieee80211_tx_queue_params *params) |
| 1716 | { |
| 1717 | struct ath_softc *sc = hw->priv; |
| 1718 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1719 | struct ath_txq *txq; |
| 1720 | struct ath9k_tx_queue_info qi; |
| 1721 | int ret = 0; |
| 1722 | |
| 1723 | if (queue >= IEEE80211_NUM_ACS) |
| 1724 | return 0; |
| 1725 | |
| 1726 | txq = sc->tx.txq_map[queue]; |
| 1727 | |
| 1728 | ath9k_ps_wakeup(sc); |
| 1729 | mutex_lock(&sc->mutex); |
| 1730 | |
| 1731 | memset(&qi, 0, sizeof(struct ath9k_tx_queue_info)); |
| 1732 | |
| 1733 | qi.tqi_aifs = params->aifs; |
| 1734 | qi.tqi_cwmin = params->cw_min; |
| 1735 | qi.tqi_cwmax = params->cw_max; |
| 1736 | qi.tqi_burstTime = params->txop * 32; |
| 1737 | |
| 1738 | ath_dbg(common, CONFIG, |
| 1739 | "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n", |
| 1740 | queue, txq->axq_qnum, params->aifs, params->cw_min, |
| 1741 | params->cw_max, params->txop); |
| 1742 | |
| 1743 | ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime); |
| 1744 | ret = ath_txq_update(sc, txq->axq_qnum, &qi); |
| 1745 | if (ret) |
| 1746 | ath_err(common, "TXQ Update failed\n"); |
| 1747 | |
| 1748 | mutex_unlock(&sc->mutex); |
| 1749 | ath9k_ps_restore(sc); |
| 1750 | |
| 1751 | return ret; |
| 1752 | } |
| 1753 | |
| 1754 | static int ath9k_set_key(struct ieee80211_hw *hw, |
| 1755 | enum set_key_cmd cmd, |
| 1756 | struct ieee80211_vif *vif, |
| 1757 | struct ieee80211_sta *sta, |
| 1758 | struct ieee80211_key_conf *key) |
| 1759 | { |
| 1760 | struct ath_softc *sc = hw->priv; |
| 1761 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1762 | struct ath_node *an = NULL; |
| 1763 | int ret = 0, i; |
| 1764 | |
| 1765 | if (ath9k_modparam_nohwcrypt) |
| 1766 | return -ENOSPC; |
| 1767 | |
| 1768 | if ((vif->type == NL80211_IFTYPE_ADHOC || |
| 1769 | vif->type == NL80211_IFTYPE_MESH_POINT) && |
| 1770 | (key->cipher == WLAN_CIPHER_SUITE_TKIP || |
| 1771 | key->cipher == WLAN_CIPHER_SUITE_CCMP) && |
| 1772 | !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 1773 | /* |
| 1774 | * For now, disable hw crypto for the RSN IBSS group keys. This |
| 1775 | * could be optimized in the future to use a modified key cache |
| 1776 | * design to support per-STA RX GTK, but until that gets |
| 1777 | * implemented, use of software crypto for group addressed |
| 1778 | * frames is a acceptable to allow RSN IBSS to be used. |
| 1779 | */ |
| 1780 | return -EOPNOTSUPP; |
| 1781 | } |
| 1782 | |
| 1783 | mutex_lock(&sc->mutex); |
| 1784 | ath9k_ps_wakeup(sc); |
| 1785 | ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd); |
| 1786 | if (sta) |
| 1787 | an = (struct ath_node *)sta->drv_priv; |
| 1788 | |
| 1789 | /* Delete pending key cache entries if no more frames are pointing to |
| 1790 | * them in TXQs. |
| 1791 | */ |
| 1792 | for (i = 0; i < ATH_KEYMAX; i++) |
| 1793 | ath9k_pending_key_del(sc, i); |
| 1794 | |
| 1795 | switch (cmd) { |
| 1796 | case SET_KEY: |
| 1797 | if (sta) |
| 1798 | ath9k_del_ps_key(sc, vif, sta); |
| 1799 | |
| 1800 | key->hw_key_idx = 0; |
| 1801 | ret = ath_key_config(common, vif, sta, key); |
| 1802 | if (ret >= 0) { |
| 1803 | key->hw_key_idx = ret; |
| 1804 | /* push IV and Michael MIC generation to stack */ |
| 1805 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 1806 | if (key->cipher == WLAN_CIPHER_SUITE_TKIP) |
| 1807 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; |
| 1808 | if (sc->sc_ah->sw_mgmt_crypto_tx && |
| 1809 | key->cipher == WLAN_CIPHER_SUITE_CCMP) |
| 1810 | key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; |
| 1811 | ret = 0; |
| 1812 | } |
| 1813 | if (an && key->hw_key_idx) { |
| 1814 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1815 | if (an->key_idx[i]) |
| 1816 | continue; |
| 1817 | an->key_idx[i] = key->hw_key_idx; |
| 1818 | break; |
| 1819 | } |
| 1820 | WARN_ON(i == ARRAY_SIZE(an->key_idx)); |
| 1821 | } |
| 1822 | break; |
| 1823 | case DISABLE_KEY: |
| 1824 | if (ath9k_txq_has_key(sc, key->hw_key_idx)) { |
| 1825 | /* Delay key cache entry deletion until there are no |
| 1826 | * remaining TXQ frames pointing to this entry. |
| 1827 | */ |
| 1828 | set_bit(key->hw_key_idx, sc->sc_ah->pending_del_keymap); |
| 1829 | ath_hw_keysetmac(common, key->hw_key_idx, NULL); |
| 1830 | } else { |
| 1831 | ath_key_delete(common, key->hw_key_idx); |
| 1832 | } |
| 1833 | if (an) { |
| 1834 | for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) { |
| 1835 | if (an->key_idx[i] != key->hw_key_idx) |
| 1836 | continue; |
| 1837 | an->key_idx[i] = 0; |
| 1838 | break; |
| 1839 | } |
| 1840 | } |
| 1841 | key->hw_key_idx = 0; |
| 1842 | break; |
| 1843 | default: |
| 1844 | ret = -EINVAL; |
| 1845 | } |
| 1846 | |
| 1847 | ath9k_ps_restore(sc); |
| 1848 | mutex_unlock(&sc->mutex); |
| 1849 | |
| 1850 | return ret; |
| 1851 | } |
| 1852 | |
| 1853 | static void ath9k_bss_info_changed(struct ieee80211_hw *hw, |
| 1854 | struct ieee80211_vif *vif, |
| 1855 | struct ieee80211_bss_conf *bss_conf, |
| 1856 | u32 changed) |
| 1857 | { |
| 1858 | #define CHECK_ANI \ |
| 1859 | (BSS_CHANGED_ASSOC | \ |
| 1860 | BSS_CHANGED_IBSS | \ |
| 1861 | BSS_CHANGED_BEACON_ENABLED) |
| 1862 | |
| 1863 | struct ath_softc *sc = hw->priv; |
| 1864 | struct ath_hw *ah = sc->sc_ah; |
| 1865 | struct ath_common *common = ath9k_hw_common(ah); |
| 1866 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1867 | int slottime; |
| 1868 | |
| 1869 | ath9k_ps_wakeup(sc); |
| 1870 | mutex_lock(&sc->mutex); |
| 1871 | |
| 1872 | if (changed & BSS_CHANGED_ASSOC) { |
| 1873 | ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n", |
| 1874 | bss_conf->bssid, bss_conf->assoc); |
| 1875 | |
| 1876 | memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN); |
| 1877 | avp->aid = bss_conf->aid; |
| 1878 | avp->assoc = bss_conf->assoc; |
| 1879 | |
| 1880 | ath9k_calculate_summary_state(sc, avp->chanctx); |
| 1881 | } |
| 1882 | |
| 1883 | if ((changed & BSS_CHANGED_IBSS) || |
| 1884 | (changed & BSS_CHANGED_OCB)) { |
| 1885 | memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); |
| 1886 | common->curaid = bss_conf->aid; |
| 1887 | ath9k_hw_write_associd(sc->sc_ah); |
| 1888 | } |
| 1889 | |
| 1890 | if ((changed & BSS_CHANGED_BEACON_ENABLED) || |
| 1891 | (changed & BSS_CHANGED_BEACON_INT) || |
| 1892 | (changed & BSS_CHANGED_BEACON_INFO)) { |
| 1893 | ath9k_calculate_summary_state(sc, avp->chanctx); |
| 1894 | } |
| 1895 | |
| 1896 | if ((avp->chanctx == sc->cur_chan) && |
| 1897 | (changed & BSS_CHANGED_ERP_SLOT)) { |
| 1898 | if (bss_conf->use_short_slot) |
| 1899 | slottime = 9; |
| 1900 | else |
| 1901 | slottime = 20; |
| 1902 | |
| 1903 | if (vif->type == NL80211_IFTYPE_AP) { |
| 1904 | /* |
| 1905 | * Defer update, so that connected stations can adjust |
| 1906 | * their settings at the same time. |
| 1907 | * See beacon.c for more details |
| 1908 | */ |
| 1909 | sc->beacon.slottime = slottime; |
| 1910 | sc->beacon.updateslot = UPDATE; |
| 1911 | } else { |
| 1912 | ah->slottime = slottime; |
| 1913 | ath9k_hw_init_global_settings(ah); |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | if (changed & BSS_CHANGED_P2P_PS) |
| 1918 | ath9k_p2p_bss_info_changed(sc, vif); |
| 1919 | |
| 1920 | if (changed & CHECK_ANI) |
| 1921 | ath_check_ani(sc); |
| 1922 | |
| 1923 | if (changed & BSS_CHANGED_TXPOWER) { |
| 1924 | ath_dbg(common, CONFIG, "vif %pM power %d dbm power_type %d\n", |
| 1925 | vif->addr, bss_conf->txpower, bss_conf->txpower_type); |
| 1926 | ath9k_set_txpower(sc, vif); |
| 1927 | } |
| 1928 | |
| 1929 | mutex_unlock(&sc->mutex); |
| 1930 | ath9k_ps_restore(sc); |
| 1931 | |
| 1932 | #undef CHECK_ANI |
| 1933 | } |
| 1934 | |
| 1935 | static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 1936 | { |
| 1937 | struct ath_softc *sc = hw->priv; |
| 1938 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1939 | u64 tsf; |
| 1940 | |
| 1941 | mutex_lock(&sc->mutex); |
| 1942 | ath9k_ps_wakeup(sc); |
| 1943 | /* Get current TSF either from HW or kernel time. */ |
| 1944 | if (sc->cur_chan == avp->chanctx) { |
| 1945 | tsf = ath9k_hw_gettsf64(sc->sc_ah); |
| 1946 | } else { |
| 1947 | tsf = sc->cur_chan->tsf_val + |
| 1948 | ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL); |
| 1949 | } |
| 1950 | tsf += le64_to_cpu(avp->tsf_adjust); |
| 1951 | ath9k_ps_restore(sc); |
| 1952 | mutex_unlock(&sc->mutex); |
| 1953 | |
| 1954 | return tsf; |
| 1955 | } |
| 1956 | |
| 1957 | static void ath9k_set_tsf(struct ieee80211_hw *hw, |
| 1958 | struct ieee80211_vif *vif, |
| 1959 | u64 tsf) |
| 1960 | { |
| 1961 | struct ath_softc *sc = hw->priv; |
| 1962 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1963 | |
| 1964 | mutex_lock(&sc->mutex); |
| 1965 | ath9k_ps_wakeup(sc); |
| 1966 | tsf -= le64_to_cpu(avp->tsf_adjust); |
| 1967 | ktime_get_raw_ts64(&avp->chanctx->tsf_ts); |
| 1968 | if (sc->cur_chan == avp->chanctx) |
| 1969 | ath9k_hw_settsf64(sc->sc_ah, tsf); |
| 1970 | avp->chanctx->tsf_val = tsf; |
| 1971 | ath9k_ps_restore(sc); |
| 1972 | mutex_unlock(&sc->mutex); |
| 1973 | } |
| 1974 | |
| 1975 | static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| 1976 | { |
| 1977 | struct ath_softc *sc = hw->priv; |
| 1978 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 1979 | |
| 1980 | mutex_lock(&sc->mutex); |
| 1981 | |
| 1982 | ath9k_ps_wakeup(sc); |
| 1983 | ktime_get_raw_ts64(&avp->chanctx->tsf_ts); |
| 1984 | if (sc->cur_chan == avp->chanctx) |
| 1985 | ath9k_hw_reset_tsf(sc->sc_ah); |
| 1986 | avp->chanctx->tsf_val = 0; |
| 1987 | ath9k_ps_restore(sc); |
| 1988 | |
| 1989 | mutex_unlock(&sc->mutex); |
| 1990 | } |
| 1991 | |
| 1992 | static int ath9k_ampdu_action(struct ieee80211_hw *hw, |
| 1993 | struct ieee80211_vif *vif, |
| 1994 | struct ieee80211_ampdu_params *params) |
| 1995 | { |
| 1996 | struct ath_softc *sc = hw->priv; |
| 1997 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 1998 | bool flush = false; |
| 1999 | int ret = 0; |
| 2000 | struct ieee80211_sta *sta = params->sta; |
| 2001 | struct ath_node *an = (struct ath_node *)sta->drv_priv; |
| 2002 | enum ieee80211_ampdu_mlme_action action = params->action; |
| 2003 | u16 tid = params->tid; |
| 2004 | u16 *ssn = ¶ms->ssn; |
| 2005 | struct ath_atx_tid *atid; |
| 2006 | |
| 2007 | mutex_lock(&sc->mutex); |
| 2008 | |
| 2009 | switch (action) { |
| 2010 | case IEEE80211_AMPDU_RX_START: |
| 2011 | break; |
| 2012 | case IEEE80211_AMPDU_RX_STOP: |
| 2013 | break; |
| 2014 | case IEEE80211_AMPDU_TX_START: |
| 2015 | if (ath9k_is_chanctx_enabled()) { |
| 2016 | if (test_bit(ATH_OP_SCANNING, &common->op_flags)) { |
| 2017 | ret = -EBUSY; |
| 2018 | break; |
| 2019 | } |
| 2020 | } |
| 2021 | ath9k_ps_wakeup(sc); |
| 2022 | ret = ath_tx_aggr_start(sc, sta, tid, ssn); |
| 2023 | if (!ret) |
| 2024 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2025 | ath9k_ps_restore(sc); |
| 2026 | break; |
| 2027 | case IEEE80211_AMPDU_TX_STOP_FLUSH: |
| 2028 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: |
| 2029 | flush = true; |
| 2030 | /* fall through */ |
| 2031 | case IEEE80211_AMPDU_TX_STOP_CONT: |
| 2032 | ath9k_ps_wakeup(sc); |
| 2033 | ath_tx_aggr_stop(sc, sta, tid); |
| 2034 | if (!flush) |
| 2035 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2036 | ath9k_ps_restore(sc); |
| 2037 | break; |
| 2038 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
| 2039 | atid = ath_node_to_tid(an, tid); |
| 2040 | atid->baw_size = IEEE80211_MIN_AMPDU_BUF << |
| 2041 | sta->ht_cap.ampdu_factor; |
| 2042 | break; |
| 2043 | default: |
| 2044 | ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n"); |
| 2045 | } |
| 2046 | |
| 2047 | mutex_unlock(&sc->mutex); |
| 2048 | |
| 2049 | return ret; |
| 2050 | } |
| 2051 | |
| 2052 | static int ath9k_get_survey(struct ieee80211_hw *hw, int idx, |
| 2053 | struct survey_info *survey) |
| 2054 | { |
| 2055 | struct ath_softc *sc = hw->priv; |
| 2056 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2057 | struct ieee80211_supported_band *sband; |
| 2058 | struct ieee80211_channel *chan; |
| 2059 | unsigned long flags; |
| 2060 | int pos; |
| 2061 | |
| 2062 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) |
| 2063 | return -EOPNOTSUPP; |
| 2064 | |
| 2065 | spin_lock_irqsave(&common->cc_lock, flags); |
| 2066 | if (idx == 0) |
| 2067 | ath_update_survey_stats(sc); |
| 2068 | |
| 2069 | sband = hw->wiphy->bands[NL80211_BAND_2GHZ]; |
| 2070 | if (sband && idx >= sband->n_channels) { |
| 2071 | idx -= sband->n_channels; |
| 2072 | sband = NULL; |
| 2073 | } |
| 2074 | |
| 2075 | if (!sband) |
| 2076 | sband = hw->wiphy->bands[NL80211_BAND_5GHZ]; |
| 2077 | |
| 2078 | if (!sband || idx >= sband->n_channels) { |
| 2079 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 2080 | return -ENOENT; |
| 2081 | } |
| 2082 | |
| 2083 | chan = &sband->channels[idx]; |
| 2084 | pos = chan->hw_value; |
| 2085 | memcpy(survey, &sc->survey[pos], sizeof(*survey)); |
| 2086 | survey->channel = chan; |
| 2087 | spin_unlock_irqrestore(&common->cc_lock, flags); |
| 2088 | |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
| 2092 | static void ath9k_enable_dynack(struct ath_softc *sc) |
| 2093 | { |
| 2094 | #ifdef CONFIG_ATH9K_DYNACK |
| 2095 | u32 rfilt; |
| 2096 | struct ath_hw *ah = sc->sc_ah; |
| 2097 | |
| 2098 | ath_dynack_reset(ah); |
| 2099 | |
| 2100 | ah->dynack.enabled = true; |
| 2101 | rfilt = ath_calcrxfilter(sc); |
| 2102 | ath9k_hw_setrxfilter(ah, rfilt); |
| 2103 | #endif |
| 2104 | } |
| 2105 | |
| 2106 | static void ath9k_set_coverage_class(struct ieee80211_hw *hw, |
| 2107 | s16 coverage_class) |
| 2108 | { |
| 2109 | struct ath_softc *sc = hw->priv; |
| 2110 | struct ath_hw *ah = sc->sc_ah; |
| 2111 | |
| 2112 | if (IS_ENABLED(CONFIG_ATH9K_TX99)) |
| 2113 | return; |
| 2114 | |
| 2115 | mutex_lock(&sc->mutex); |
| 2116 | |
| 2117 | if (coverage_class >= 0) { |
| 2118 | ah->coverage_class = coverage_class; |
| 2119 | if (ah->dynack.enabled) { |
| 2120 | u32 rfilt; |
| 2121 | |
| 2122 | ah->dynack.enabled = false; |
| 2123 | rfilt = ath_calcrxfilter(sc); |
| 2124 | ath9k_hw_setrxfilter(ah, rfilt); |
| 2125 | } |
| 2126 | ath9k_ps_wakeup(sc); |
| 2127 | ath9k_hw_init_global_settings(ah); |
| 2128 | ath9k_ps_restore(sc); |
| 2129 | } else if (!ah->dynack.enabled) { |
| 2130 | ath9k_enable_dynack(sc); |
| 2131 | } |
| 2132 | |
| 2133 | mutex_unlock(&sc->mutex); |
| 2134 | } |
| 2135 | |
| 2136 | static bool ath9k_has_tx_pending(struct ath_softc *sc, |
| 2137 | bool sw_pending) |
| 2138 | { |
| 2139 | int i, npend = 0; |
| 2140 | |
| 2141 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) { |
| 2142 | if (!ATH_TXQ_SETUP(sc, i)) |
| 2143 | continue; |
| 2144 | |
| 2145 | npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i], |
| 2146 | sw_pending); |
| 2147 | if (npend) |
| 2148 | break; |
| 2149 | } |
| 2150 | |
| 2151 | return !!npend; |
| 2152 | } |
| 2153 | |
| 2154 | static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 2155 | u32 queues, bool drop) |
| 2156 | { |
| 2157 | struct ath_softc *sc = hw->priv; |
| 2158 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2159 | |
| 2160 | if (ath9k_is_chanctx_enabled()) { |
| 2161 | if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) |
| 2162 | goto flush; |
| 2163 | |
| 2164 | /* |
| 2165 | * If MCC is active, extend the flush timeout |
| 2166 | * and wait for the HW/SW queues to become |
| 2167 | * empty. This needs to be done outside the |
| 2168 | * sc->mutex lock to allow the channel scheduler |
| 2169 | * to switch channel contexts. |
| 2170 | * |
| 2171 | * The vif queues have been stopped in mac80211, |
| 2172 | * so there won't be any incoming frames. |
| 2173 | */ |
| 2174 | __ath9k_flush(hw, queues, drop, true, true); |
| 2175 | return; |
| 2176 | } |
| 2177 | flush: |
| 2178 | mutex_lock(&sc->mutex); |
| 2179 | __ath9k_flush(hw, queues, drop, true, false); |
| 2180 | mutex_unlock(&sc->mutex); |
| 2181 | } |
| 2182 | |
| 2183 | void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop, |
| 2184 | bool sw_pending, bool timeout_override) |
| 2185 | { |
| 2186 | struct ath_softc *sc = hw->priv; |
| 2187 | struct ath_hw *ah = sc->sc_ah; |
| 2188 | struct ath_common *common = ath9k_hw_common(ah); |
| 2189 | int timeout; |
| 2190 | bool drain_txq; |
| 2191 | |
| 2192 | cancel_delayed_work_sync(&sc->hw_check_work); |
| 2193 | |
| 2194 | if (ah->ah_flags & AH_UNPLUGGED) { |
| 2195 | ath_dbg(common, ANY, "Device has been unplugged!\n"); |
| 2196 | return; |
| 2197 | } |
| 2198 | |
| 2199 | if (test_bit(ATH_OP_INVALID, &common->op_flags)) { |
| 2200 | ath_dbg(common, ANY, "Device not present\n"); |
| 2201 | return; |
| 2202 | } |
| 2203 | |
| 2204 | spin_lock_bh(&sc->chan_lock); |
| 2205 | if (timeout_override) |
| 2206 | timeout = HZ / 5; |
| 2207 | else |
| 2208 | timeout = sc->cur_chan->flush_timeout; |
| 2209 | spin_unlock_bh(&sc->chan_lock); |
| 2210 | |
| 2211 | ath_dbg(common, CHAN_CTX, |
| 2212 | "Flush timeout: %d\n", jiffies_to_msecs(timeout)); |
| 2213 | |
| 2214 | if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc, sw_pending), |
| 2215 | timeout) > 0) |
| 2216 | drop = false; |
| 2217 | |
| 2218 | if (drop) { |
| 2219 | ath9k_ps_wakeup(sc); |
| 2220 | spin_lock_bh(&sc->sc_pcu_lock); |
| 2221 | drain_txq = ath_drain_all_txq(sc); |
| 2222 | spin_unlock_bh(&sc->sc_pcu_lock); |
| 2223 | |
| 2224 | if (!drain_txq) |
| 2225 | ath_reset(sc, NULL); |
| 2226 | |
| 2227 | ath9k_ps_restore(sc); |
| 2228 | } |
| 2229 | |
| 2230 | ieee80211_queue_delayed_work(hw, &sc->hw_check_work, |
| 2231 | msecs_to_jiffies(ATH_HW_CHECK_POLL_INT)); |
| 2232 | } |
| 2233 | |
| 2234 | static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw) |
| 2235 | { |
| 2236 | struct ath_softc *sc = hw->priv; |
| 2237 | |
| 2238 | return ath9k_has_tx_pending(sc, true); |
| 2239 | } |
| 2240 | |
| 2241 | static int ath9k_tx_last_beacon(struct ieee80211_hw *hw) |
| 2242 | { |
| 2243 | struct ath_softc *sc = hw->priv; |
| 2244 | struct ath_hw *ah = sc->sc_ah; |
| 2245 | struct ieee80211_vif *vif; |
| 2246 | struct ath_vif *avp; |
| 2247 | struct ath_buf *bf; |
| 2248 | struct ath_tx_status ts; |
| 2249 | bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); |
| 2250 | int status; |
| 2251 | |
| 2252 | vif = sc->beacon.bslot[0]; |
| 2253 | if (!vif) |
| 2254 | return 0; |
| 2255 | |
| 2256 | if (!vif->bss_conf.enable_beacon) |
| 2257 | return 0; |
| 2258 | |
| 2259 | avp = (void *)vif->drv_priv; |
| 2260 | |
| 2261 | if (!sc->beacon.tx_processed && !edma) { |
| 2262 | tasklet_disable(&sc->bcon_tasklet); |
| 2263 | |
| 2264 | bf = avp->av_bcbuf; |
| 2265 | if (!bf || !bf->bf_mpdu) |
| 2266 | goto skip; |
| 2267 | |
| 2268 | status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts); |
| 2269 | if (status == -EINPROGRESS) |
| 2270 | goto skip; |
| 2271 | |
| 2272 | sc->beacon.tx_processed = true; |
| 2273 | sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK); |
| 2274 | |
| 2275 | skip: |
| 2276 | tasklet_enable(&sc->bcon_tasklet); |
| 2277 | } |
| 2278 | |
| 2279 | return sc->beacon.tx_last; |
| 2280 | } |
| 2281 | |
| 2282 | static int ath9k_get_stats(struct ieee80211_hw *hw, |
| 2283 | struct ieee80211_low_level_stats *stats) |
| 2284 | { |
| 2285 | struct ath_softc *sc = hw->priv; |
| 2286 | struct ath_hw *ah = sc->sc_ah; |
| 2287 | struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats; |
| 2288 | |
| 2289 | stats->dot11ACKFailureCount = mib_stats->ackrcv_bad; |
| 2290 | stats->dot11RTSFailureCount = mib_stats->rts_bad; |
| 2291 | stats->dot11FCSErrorCount = mib_stats->fcs_bad; |
| 2292 | stats->dot11RTSSuccessCount = mib_stats->rts_good; |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
| 2296 | static u32 fill_chainmask(u32 cap, u32 new) |
| 2297 | { |
| 2298 | u32 filled = 0; |
| 2299 | int i; |
| 2300 | |
| 2301 | for (i = 0; cap && new; i++, cap >>= 1) { |
| 2302 | if (!(cap & BIT(0))) |
| 2303 | continue; |
| 2304 | |
| 2305 | if (new & BIT(0)) |
| 2306 | filled |= BIT(i); |
| 2307 | |
| 2308 | new >>= 1; |
| 2309 | } |
| 2310 | |
| 2311 | return filled; |
| 2312 | } |
| 2313 | |
| 2314 | static bool validate_antenna_mask(struct ath_hw *ah, u32 val) |
| 2315 | { |
| 2316 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 2317 | return true; |
| 2318 | |
| 2319 | switch (val & 0x7) { |
| 2320 | case 0x1: |
| 2321 | case 0x3: |
| 2322 | case 0x7: |
| 2323 | return true; |
| 2324 | case 0x2: |
| 2325 | return (ah->caps.rx_chainmask == 1); |
| 2326 | default: |
| 2327 | return false; |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) |
| 2332 | { |
| 2333 | struct ath_softc *sc = hw->priv; |
| 2334 | struct ath_hw *ah = sc->sc_ah; |
| 2335 | |
| 2336 | if (ah->caps.rx_chainmask != 1) |
| 2337 | rx_ant |= tx_ant; |
| 2338 | |
| 2339 | if (!validate_antenna_mask(ah, rx_ant) || !tx_ant) |
| 2340 | return -EINVAL; |
| 2341 | |
| 2342 | sc->ant_rx = rx_ant; |
| 2343 | sc->ant_tx = tx_ant; |
| 2344 | |
| 2345 | if (ah->caps.rx_chainmask == 1) |
| 2346 | return 0; |
| 2347 | |
| 2348 | /* AR9100 runs into calibration issues if not all rx chains are enabled */ |
| 2349 | if (AR_SREV_9100(ah)) |
| 2350 | ah->rxchainmask = 0x7; |
| 2351 | else |
| 2352 | ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant); |
| 2353 | |
| 2354 | ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant); |
| 2355 | ath9k_cmn_reload_chainmask(ah); |
| 2356 | |
| 2357 | return 0; |
| 2358 | } |
| 2359 | |
| 2360 | static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) |
| 2361 | { |
| 2362 | struct ath_softc *sc = hw->priv; |
| 2363 | |
| 2364 | *tx_ant = sc->ant_tx; |
| 2365 | *rx_ant = sc->ant_rx; |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | static void ath9k_sw_scan_start(struct ieee80211_hw *hw, |
| 2370 | struct ieee80211_vif *vif, |
| 2371 | const u8 *mac_addr) |
| 2372 | { |
| 2373 | struct ath_softc *sc = hw->priv; |
| 2374 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2375 | set_bit(ATH_OP_SCANNING, &common->op_flags); |
| 2376 | } |
| 2377 | |
| 2378 | static void ath9k_sw_scan_complete(struct ieee80211_hw *hw, |
| 2379 | struct ieee80211_vif *vif) |
| 2380 | { |
| 2381 | struct ath_softc *sc = hw->priv; |
| 2382 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2383 | clear_bit(ATH_OP_SCANNING, &common->op_flags); |
| 2384 | } |
| 2385 | |
| 2386 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 2387 | |
| 2388 | static void ath9k_cancel_pending_offchannel(struct ath_softc *sc) |
| 2389 | { |
| 2390 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2391 | |
| 2392 | if (sc->offchannel.roc_vif) { |
| 2393 | ath_dbg(common, CHAN_CTX, |
| 2394 | "%s: Aborting RoC\n", __func__); |
| 2395 | |
| 2396 | del_timer_sync(&sc->offchannel.timer); |
| 2397 | if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START) |
| 2398 | ath_roc_complete(sc, ATH_ROC_COMPLETE_ABORT); |
| 2399 | } |
| 2400 | |
| 2401 | if (test_bit(ATH_OP_SCANNING, &common->op_flags)) { |
| 2402 | ath_dbg(common, CHAN_CTX, |
| 2403 | "%s: Aborting HW scan\n", __func__); |
| 2404 | |
| 2405 | del_timer_sync(&sc->offchannel.timer); |
| 2406 | ath_scan_complete(sc, true); |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 2411 | struct ieee80211_scan_request *hw_req) |
| 2412 | { |
| 2413 | struct cfg80211_scan_request *req = &hw_req->req; |
| 2414 | struct ath_softc *sc = hw->priv; |
| 2415 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2416 | int ret = 0; |
| 2417 | |
| 2418 | mutex_lock(&sc->mutex); |
| 2419 | |
| 2420 | if (WARN_ON(sc->offchannel.scan_req)) { |
| 2421 | ret = -EBUSY; |
| 2422 | goto out; |
| 2423 | } |
| 2424 | |
| 2425 | ath9k_ps_wakeup(sc); |
| 2426 | set_bit(ATH_OP_SCANNING, &common->op_flags); |
| 2427 | sc->offchannel.scan_vif = vif; |
| 2428 | sc->offchannel.scan_req = req; |
| 2429 | sc->offchannel.scan_idx = 0; |
| 2430 | |
| 2431 | ath_dbg(common, CHAN_CTX, "HW scan request received on vif: %pM\n", |
| 2432 | vif->addr); |
| 2433 | |
| 2434 | if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) { |
| 2435 | ath_dbg(common, CHAN_CTX, "Starting HW scan\n"); |
| 2436 | ath_offchannel_next(sc); |
| 2437 | } |
| 2438 | |
| 2439 | out: |
| 2440 | mutex_unlock(&sc->mutex); |
| 2441 | |
| 2442 | return ret; |
| 2443 | } |
| 2444 | |
| 2445 | static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw, |
| 2446 | struct ieee80211_vif *vif) |
| 2447 | { |
| 2448 | struct ath_softc *sc = hw->priv; |
| 2449 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2450 | |
| 2451 | ath_dbg(common, CHAN_CTX, "Cancel HW scan on vif: %pM\n", vif->addr); |
| 2452 | |
| 2453 | mutex_lock(&sc->mutex); |
| 2454 | del_timer_sync(&sc->offchannel.timer); |
| 2455 | ath_scan_complete(sc, true); |
| 2456 | mutex_unlock(&sc->mutex); |
| 2457 | } |
| 2458 | |
| 2459 | static int ath9k_remain_on_channel(struct ieee80211_hw *hw, |
| 2460 | struct ieee80211_vif *vif, |
| 2461 | struct ieee80211_channel *chan, int duration, |
| 2462 | enum ieee80211_roc_type type) |
| 2463 | { |
| 2464 | struct ath_softc *sc = hw->priv; |
| 2465 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2466 | int ret = 0; |
| 2467 | |
| 2468 | mutex_lock(&sc->mutex); |
| 2469 | |
| 2470 | if (WARN_ON(sc->offchannel.roc_vif)) { |
| 2471 | ret = -EBUSY; |
| 2472 | goto out; |
| 2473 | } |
| 2474 | |
| 2475 | ath9k_ps_wakeup(sc); |
| 2476 | sc->offchannel.roc_vif = vif; |
| 2477 | sc->offchannel.roc_chan = chan; |
| 2478 | sc->offchannel.roc_duration = duration; |
| 2479 | |
| 2480 | ath_dbg(common, CHAN_CTX, |
| 2481 | "RoC request on vif: %pM, type: %d duration: %d\n", |
| 2482 | vif->addr, type, duration); |
| 2483 | |
| 2484 | if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) { |
| 2485 | ath_dbg(common, CHAN_CTX, "Starting RoC period\n"); |
| 2486 | ath_offchannel_next(sc); |
| 2487 | } |
| 2488 | |
| 2489 | out: |
| 2490 | mutex_unlock(&sc->mutex); |
| 2491 | |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
| 2495 | static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw, |
| 2496 | struct ieee80211_vif *vif) |
| 2497 | { |
| 2498 | struct ath_softc *sc = hw->priv; |
| 2499 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2500 | |
| 2501 | mutex_lock(&sc->mutex); |
| 2502 | |
| 2503 | ath_dbg(common, CHAN_CTX, "Cancel RoC\n"); |
| 2504 | del_timer_sync(&sc->offchannel.timer); |
| 2505 | |
| 2506 | if (sc->offchannel.roc_vif) { |
| 2507 | if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START) |
| 2508 | ath_roc_complete(sc, ATH_ROC_COMPLETE_CANCEL); |
| 2509 | } |
| 2510 | |
| 2511 | mutex_unlock(&sc->mutex); |
| 2512 | |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | static int ath9k_add_chanctx(struct ieee80211_hw *hw, |
| 2517 | struct ieee80211_chanctx_conf *conf) |
| 2518 | { |
| 2519 | struct ath_softc *sc = hw->priv; |
| 2520 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2521 | struct ath_chanctx *ctx, **ptr; |
| 2522 | int pos; |
| 2523 | |
| 2524 | mutex_lock(&sc->mutex); |
| 2525 | |
| 2526 | ath_for_each_chanctx(sc, ctx) { |
| 2527 | if (ctx->assigned) |
| 2528 | continue; |
| 2529 | |
| 2530 | ptr = (void *) conf->drv_priv; |
| 2531 | *ptr = ctx; |
| 2532 | ctx->assigned = true; |
| 2533 | pos = ctx - &sc->chanctx[0]; |
| 2534 | ctx->hw_queue_base = pos * IEEE80211_NUM_ACS; |
| 2535 | |
| 2536 | ath_dbg(common, CHAN_CTX, |
| 2537 | "Add channel context: %d MHz\n", |
| 2538 | conf->def.chan->center_freq); |
| 2539 | |
| 2540 | ath_chanctx_set_channel(sc, ctx, &conf->def); |
| 2541 | |
| 2542 | mutex_unlock(&sc->mutex); |
| 2543 | return 0; |
| 2544 | } |
| 2545 | |
| 2546 | mutex_unlock(&sc->mutex); |
| 2547 | return -ENOSPC; |
| 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | static void ath9k_remove_chanctx(struct ieee80211_hw *hw, |
| 2552 | struct ieee80211_chanctx_conf *conf) |
| 2553 | { |
| 2554 | struct ath_softc *sc = hw->priv; |
| 2555 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2556 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2557 | |
| 2558 | mutex_lock(&sc->mutex); |
| 2559 | |
| 2560 | ath_dbg(common, CHAN_CTX, |
| 2561 | "Remove channel context: %d MHz\n", |
| 2562 | conf->def.chan->center_freq); |
| 2563 | |
| 2564 | ctx->assigned = false; |
| 2565 | ctx->hw_queue_base = 0; |
| 2566 | ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN); |
| 2567 | |
| 2568 | mutex_unlock(&sc->mutex); |
| 2569 | } |
| 2570 | |
| 2571 | static void ath9k_change_chanctx(struct ieee80211_hw *hw, |
| 2572 | struct ieee80211_chanctx_conf *conf, |
| 2573 | u32 changed) |
| 2574 | { |
| 2575 | struct ath_softc *sc = hw->priv; |
| 2576 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2577 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2578 | |
| 2579 | mutex_lock(&sc->mutex); |
| 2580 | ath_dbg(common, CHAN_CTX, |
| 2581 | "Change channel context: %d MHz\n", |
| 2582 | conf->def.chan->center_freq); |
| 2583 | ath_chanctx_set_channel(sc, ctx, &conf->def); |
| 2584 | mutex_unlock(&sc->mutex); |
| 2585 | } |
| 2586 | |
| 2587 | static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw, |
| 2588 | struct ieee80211_vif *vif, |
| 2589 | struct ieee80211_chanctx_conf *conf) |
| 2590 | { |
| 2591 | struct ath_softc *sc = hw->priv; |
| 2592 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2593 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2594 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2595 | int i; |
| 2596 | |
| 2597 | ath9k_cancel_pending_offchannel(sc); |
| 2598 | |
| 2599 | mutex_lock(&sc->mutex); |
| 2600 | |
| 2601 | ath_dbg(common, CHAN_CTX, |
| 2602 | "Assign VIF (addr: %pM, type: %d, p2p: %d) to channel context: %d MHz\n", |
| 2603 | vif->addr, vif->type, vif->p2p, |
| 2604 | conf->def.chan->center_freq); |
| 2605 | |
| 2606 | avp->chanctx = ctx; |
| 2607 | ctx->nvifs_assigned++; |
| 2608 | list_add_tail(&avp->list, &ctx->vifs); |
| 2609 | ath9k_calculate_summary_state(sc, ctx); |
| 2610 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 2611 | vif->hw_queue[i] = ctx->hw_queue_base + i; |
| 2612 | |
| 2613 | mutex_unlock(&sc->mutex); |
| 2614 | |
| 2615 | return 0; |
| 2616 | } |
| 2617 | |
| 2618 | static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw, |
| 2619 | struct ieee80211_vif *vif, |
| 2620 | struct ieee80211_chanctx_conf *conf) |
| 2621 | { |
| 2622 | struct ath_softc *sc = hw->priv; |
| 2623 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2624 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2625 | struct ath_chanctx *ctx = ath_chanctx_get(conf); |
| 2626 | int ac; |
| 2627 | |
| 2628 | ath9k_cancel_pending_offchannel(sc); |
| 2629 | |
| 2630 | mutex_lock(&sc->mutex); |
| 2631 | |
| 2632 | ath_dbg(common, CHAN_CTX, |
| 2633 | "Remove VIF (addr: %pM, type: %d, p2p: %d) from channel context: %d MHz\n", |
| 2634 | vif->addr, vif->type, vif->p2p, |
| 2635 | conf->def.chan->center_freq); |
| 2636 | |
| 2637 | avp->chanctx = NULL; |
| 2638 | ctx->nvifs_assigned--; |
| 2639 | list_del(&avp->list); |
| 2640 | ath9k_calculate_summary_state(sc, ctx); |
| 2641 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) |
| 2642 | vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE; |
| 2643 | |
| 2644 | mutex_unlock(&sc->mutex); |
| 2645 | } |
| 2646 | |
| 2647 | static void ath9k_mgd_prepare_tx(struct ieee80211_hw *hw, |
| 2648 | struct ieee80211_vif *vif, |
| 2649 | u16 duration) |
| 2650 | { |
| 2651 | struct ath_softc *sc = hw->priv; |
| 2652 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 2653 | struct ath_vif *avp = (struct ath_vif *) vif->drv_priv; |
| 2654 | struct ath_beacon_config *cur_conf; |
| 2655 | struct ath_chanctx *go_ctx; |
| 2656 | unsigned long timeout; |
| 2657 | bool changed = false; |
| 2658 | u32 beacon_int; |
| 2659 | |
| 2660 | if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags)) |
| 2661 | return; |
| 2662 | |
| 2663 | if (!avp->chanctx) |
| 2664 | return; |
| 2665 | |
| 2666 | mutex_lock(&sc->mutex); |
| 2667 | |
| 2668 | spin_lock_bh(&sc->chan_lock); |
| 2669 | if (sc->next_chan || (sc->cur_chan != avp->chanctx)) |
| 2670 | changed = true; |
| 2671 | spin_unlock_bh(&sc->chan_lock); |
| 2672 | |
| 2673 | if (!changed) |
| 2674 | goto out; |
| 2675 | |
| 2676 | ath9k_cancel_pending_offchannel(sc); |
| 2677 | |
| 2678 | go_ctx = ath_is_go_chanctx_present(sc); |
| 2679 | |
| 2680 | if (go_ctx) { |
| 2681 | /* |
| 2682 | * Wait till the GO interface gets a chance |
| 2683 | * to send out an NoA. |
| 2684 | */ |
| 2685 | spin_lock_bh(&sc->chan_lock); |
| 2686 | sc->sched.mgd_prepare_tx = true; |
| 2687 | cur_conf = &go_ctx->beacon; |
| 2688 | beacon_int = TU_TO_USEC(cur_conf->beacon_interval); |
| 2689 | spin_unlock_bh(&sc->chan_lock); |
| 2690 | |
| 2691 | timeout = usecs_to_jiffies(beacon_int * 2); |
| 2692 | init_completion(&sc->go_beacon); |
| 2693 | |
| 2694 | mutex_unlock(&sc->mutex); |
| 2695 | |
| 2696 | if (wait_for_completion_timeout(&sc->go_beacon, |
| 2697 | timeout) == 0) { |
| 2698 | ath_dbg(common, CHAN_CTX, |
| 2699 | "Failed to send new NoA\n"); |
| 2700 | |
| 2701 | spin_lock_bh(&sc->chan_lock); |
| 2702 | sc->sched.mgd_prepare_tx = false; |
| 2703 | spin_unlock_bh(&sc->chan_lock); |
| 2704 | } |
| 2705 | |
| 2706 | mutex_lock(&sc->mutex); |
| 2707 | } |
| 2708 | |
| 2709 | ath_dbg(common, CHAN_CTX, |
| 2710 | "%s: Set chanctx state to FORCE_ACTIVE for vif: %pM\n", |
| 2711 | __func__, vif->addr); |
| 2712 | |
| 2713 | spin_lock_bh(&sc->chan_lock); |
| 2714 | sc->next_chan = avp->chanctx; |
| 2715 | sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE; |
| 2716 | spin_unlock_bh(&sc->chan_lock); |
| 2717 | |
| 2718 | ath_chanctx_set_next(sc, true); |
| 2719 | out: |
| 2720 | mutex_unlock(&sc->mutex); |
| 2721 | } |
| 2722 | |
| 2723 | void ath9k_fill_chanctx_ops(void) |
| 2724 | { |
| 2725 | if (!ath9k_is_chanctx_enabled()) |
| 2726 | return; |
| 2727 | |
| 2728 | ath9k_ops.hw_scan = ath9k_hw_scan; |
| 2729 | ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan; |
| 2730 | ath9k_ops.remain_on_channel = ath9k_remain_on_channel; |
| 2731 | ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel; |
| 2732 | ath9k_ops.add_chanctx = ath9k_add_chanctx; |
| 2733 | ath9k_ops.remove_chanctx = ath9k_remove_chanctx; |
| 2734 | ath9k_ops.change_chanctx = ath9k_change_chanctx; |
| 2735 | ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx; |
| 2736 | ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx; |
| 2737 | ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx; |
| 2738 | } |
| 2739 | |
| 2740 | #endif |
| 2741 | |
| 2742 | static int ath9k_get_txpower(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 2743 | int *dbm) |
| 2744 | { |
| 2745 | struct ath_softc *sc = hw->priv; |
| 2746 | struct ath_vif *avp = (void *)vif->drv_priv; |
| 2747 | |
| 2748 | mutex_lock(&sc->mutex); |
| 2749 | if (avp->chanctx) |
| 2750 | *dbm = avp->chanctx->cur_txpower; |
| 2751 | else |
| 2752 | *dbm = sc->cur_chan->cur_txpower; |
| 2753 | mutex_unlock(&sc->mutex); |
| 2754 | |
| 2755 | *dbm /= 2; |
| 2756 | |
| 2757 | return 0; |
| 2758 | } |
| 2759 | |
| 2760 | struct ieee80211_ops ath9k_ops = { |
| 2761 | .tx = ath9k_tx, |
| 2762 | .start = ath9k_start, |
| 2763 | .stop = ath9k_stop, |
| 2764 | .add_interface = ath9k_add_interface, |
| 2765 | .change_interface = ath9k_change_interface, |
| 2766 | .remove_interface = ath9k_remove_interface, |
| 2767 | .config = ath9k_config, |
| 2768 | .configure_filter = ath9k_configure_filter, |
| 2769 | .sta_state = ath9k_sta_state, |
| 2770 | .sta_notify = ath9k_sta_notify, |
| 2771 | .conf_tx = ath9k_conf_tx, |
| 2772 | .bss_info_changed = ath9k_bss_info_changed, |
| 2773 | .set_key = ath9k_set_key, |
| 2774 | .get_tsf = ath9k_get_tsf, |
| 2775 | .set_tsf = ath9k_set_tsf, |
| 2776 | .reset_tsf = ath9k_reset_tsf, |
| 2777 | .ampdu_action = ath9k_ampdu_action, |
| 2778 | .get_survey = ath9k_get_survey, |
| 2779 | .rfkill_poll = ath9k_rfkill_poll_state, |
| 2780 | .set_coverage_class = ath9k_set_coverage_class, |
| 2781 | .flush = ath9k_flush, |
| 2782 | .tx_frames_pending = ath9k_tx_frames_pending, |
| 2783 | .tx_last_beacon = ath9k_tx_last_beacon, |
| 2784 | .release_buffered_frames = ath9k_release_buffered_frames, |
| 2785 | .get_stats = ath9k_get_stats, |
| 2786 | .set_antenna = ath9k_set_antenna, |
| 2787 | .get_antenna = ath9k_get_antenna, |
| 2788 | |
| 2789 | #ifdef CONFIG_ATH9K_WOW |
| 2790 | .suspend = ath9k_suspend, |
| 2791 | .resume = ath9k_resume, |
| 2792 | .set_wakeup = ath9k_set_wakeup, |
| 2793 | #endif |
| 2794 | |
| 2795 | #ifdef CONFIG_ATH9K_DEBUGFS |
| 2796 | .get_et_sset_count = ath9k_get_et_sset_count, |
| 2797 | .get_et_stats = ath9k_get_et_stats, |
| 2798 | .get_et_strings = ath9k_get_et_strings, |
| 2799 | #endif |
| 2800 | |
| 2801 | #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS) |
| 2802 | .sta_add_debugfs = ath9k_sta_add_debugfs, |
| 2803 | #endif |
| 2804 | .sw_scan_start = ath9k_sw_scan_start, |
| 2805 | .sw_scan_complete = ath9k_sw_scan_complete, |
| 2806 | .get_txpower = ath9k_get_txpower, |
| 2807 | .wake_tx_queue = ath9k_wake_tx_queue, |
| 2808 | }; |