2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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.
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.
17 #include <linux/nl80211.h>
18 #include <linux/delay.h>
22 u8 ath9k_parse_mpdudensity(u8 mpdudensity)
25 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
26 * 0 for no restriction
35 switch (mpdudensity) {
41 /* Our lower layer calculations limit our precision to
57 static bool ath9k_has_pending_frames(struct ath_softc *sc, struct ath_txq *txq,
62 spin_lock_bh(&txq->axq_lock);
72 if (txq->mac80211_qnum >= 0) {
73 struct list_head *list;
75 list = &sc->cur_chan->acq[txq->mac80211_qnum];
76 if (!list_empty(list))
80 spin_unlock_bh(&txq->axq_lock);
84 static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
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);
96 void ath_ps_full_sleep(unsigned long data)
98 struct ath_softc *sc = (struct ath_softc *) data;
99 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
102 spin_lock(&common->cc_lock);
103 ath_hw_cycle_counters_update(common);
104 spin_unlock(&common->cc_lock);
106 ath9k_hw_setrxabort(sc->sc_ah, 1);
107 ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
109 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
112 void ath9k_ps_wakeup(struct ath_softc *sc)
114 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
116 enum ath9k_power_mode power_mode;
118 spin_lock_irqsave(&sc->sc_pm_lock, flags);
119 if (++sc->ps_usecount != 1)
122 del_timer_sync(&sc->sleep_timer);
123 power_mode = sc->sc_ah->power_mode;
124 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
127 * While the hardware is asleep, the cycle counters contain no
128 * useful data. Better clear them now so that they don't mess up
129 * survey data results.
131 if (power_mode != ATH9K_PM_AWAKE) {
132 spin_lock(&common->cc_lock);
133 ath_hw_cycle_counters_update(common);
134 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
135 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
136 spin_unlock(&common->cc_lock);
140 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
143 void ath9k_ps_restore(struct ath_softc *sc)
145 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
146 enum ath9k_power_mode mode;
149 spin_lock_irqsave(&sc->sc_pm_lock, flags);
150 if (--sc->ps_usecount != 0)
154 mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
158 if (sc->ps_enabled &&
159 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
161 PS_WAIT_FOR_PSPOLL_DATA |
164 mode = ATH9K_PM_NETWORK_SLEEP;
165 if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
166 ath9k_btcoex_stop_gen_timer(sc);
171 spin_lock(&common->cc_lock);
172 ath_hw_cycle_counters_update(common);
173 spin_unlock(&common->cc_lock);
175 ath9k_hw_setpower(sc->sc_ah, mode);
178 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
181 static void __ath_cancel_work(struct ath_softc *sc)
183 cancel_work_sync(&sc->paprd_work);
184 cancel_delayed_work_sync(&sc->tx_complete_work);
185 cancel_delayed_work_sync(&sc->hw_pll_work);
187 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
188 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
189 cancel_work_sync(&sc->mci_work);
193 void ath_cancel_work(struct ath_softc *sc)
195 __ath_cancel_work(sc);
196 cancel_work_sync(&sc->hw_reset_work);
199 void ath_restart_work(struct ath_softc *sc)
201 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
203 if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
204 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
205 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
210 static bool ath_prepare_reset(struct ath_softc *sc)
212 struct ath_hw *ah = sc->sc_ah;
215 ieee80211_stop_queues(sc->hw);
217 ath9k_hw_disable_interrupts(ah);
219 if (!ath_drain_all_txq(sc))
222 if (!ath_stoprecv(sc))
228 static bool ath_complete_reset(struct ath_softc *sc, bool start)
230 struct ath_hw *ah = sc->sc_ah;
231 struct ath_common *common = ath9k_hw_common(ah);
234 ath9k_calculate_summary_state(sc, sc->cur_chan);
236 ath9k_cmn_update_txpow(ah, sc->curtxpow,
237 sc->cur_chan->txpower, &sc->curtxpow);
238 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
240 if (!sc->cur_chan->offchannel && start) {
241 /* restore per chanctx TSF timer */
242 if (sc->cur_chan->tsf_val) {
245 offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts,
247 ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset);
251 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
254 if (ah->opmode == NL80211_IFTYPE_STATION &&
255 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
256 spin_lock_irqsave(&sc->sc_pm_lock, flags);
257 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
258 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
260 ath9k_set_beacon(sc);
263 ath_restart_work(sc);
264 ath_txq_schedule_all(sc);
269 ath9k_hw_set_interrupts(ah);
270 ath9k_hw_enable_interrupts(ah);
271 ieee80211_wake_queues(sc->hw);
272 ath9k_p2p_ps_timer(sc);
277 static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan)
279 struct ath_hw *ah = sc->sc_ah;
280 struct ath_common *common = ath9k_hw_common(ah);
281 struct ath9k_hw_cal_data *caldata = NULL;
285 __ath_cancel_work(sc);
287 tasklet_disable(&sc->intr_tq);
288 tasklet_disable(&sc->bcon_tasklet);
289 spin_lock_bh(&sc->sc_pcu_lock);
291 if (!sc->cur_chan->offchannel) {
293 caldata = &sc->cur_chan->caldata;
301 if (!ath_prepare_reset(sc))
304 if (ath9k_is_chanctx_enabled())
307 spin_lock_bh(&sc->chan_lock);
308 sc->cur_chandef = sc->cur_chan->chandef;
309 spin_unlock_bh(&sc->chan_lock);
311 ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
312 hchan->channel, IS_CHAN_HT40(hchan), fastcc);
314 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
317 "Unable to reset channel, reset status %d\n", r);
319 ath9k_hw_enable_interrupts(ah);
320 ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
325 if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
326 sc->cur_chan->offchannel)
327 ath9k_mci_set_txpower(sc, true, false);
329 if (!ath_complete_reset(sc, true))
333 spin_unlock_bh(&sc->sc_pcu_lock);
334 tasklet_enable(&sc->bcon_tasklet);
335 tasklet_enable(&sc->intr_tq);
340 static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
341 struct ieee80211_vif *vif)
344 an = (struct ath_node *)sta->drv_priv;
349 memset(&an->key_idx, 0, sizeof(an->key_idx));
351 ath_tx_node_init(sc, an);
353 ath_dynack_node_init(sc->sc_ah, an);
356 static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
358 struct ath_node *an = (struct ath_node *)sta->drv_priv;
359 ath_tx_node_cleanup(sc, an);
361 ath_dynack_node_deinit(sc->sc_ah, an);
364 void ath9k_tasklet(unsigned long data)
366 struct ath_softc *sc = (struct ath_softc *)data;
367 struct ath_hw *ah = sc->sc_ah;
368 struct ath_common *common = ath9k_hw_common(ah);
369 enum ath_reset_type type;
371 u32 status = sc->intrstatus;
375 spin_lock(&sc->sc_pcu_lock);
377 if (status & ATH9K_INT_FATAL) {
378 type = RESET_TYPE_FATAL_INT;
379 ath9k_queue_reset(sc, type);
382 * Increment the ref. counter here so that
383 * interrupts are enabled in the reset routine.
385 atomic_inc(&ah->intr_ref_cnt);
386 ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
390 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
391 (status & ATH9K_INT_BB_WATCHDOG)) {
392 spin_lock(&common->cc_lock);
393 ath_hw_cycle_counters_update(common);
394 ar9003_hw_bb_watchdog_dbg_info(ah);
395 spin_unlock(&common->cc_lock);
397 if (ar9003_hw_bb_watchdog_check(ah)) {
398 type = RESET_TYPE_BB_WATCHDOG;
399 ath9k_queue_reset(sc, type);
402 * Increment the ref. counter here so that
403 * interrupts are enabled in the reset routine.
405 atomic_inc(&ah->intr_ref_cnt);
406 ath_dbg(common, RESET,
407 "BB_WATCHDOG: Skipping interrupts\n");
412 if (status & ATH9K_INT_GTT) {
415 if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
416 type = RESET_TYPE_TX_GTT;
417 ath9k_queue_reset(sc, type);
418 atomic_inc(&ah->intr_ref_cnt);
419 ath_dbg(common, RESET,
420 "GTT: Skipping interrupts\n");
425 spin_lock_irqsave(&sc->sc_pm_lock, flags);
426 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
428 * TSF sync does not look correct; remain awake to sync with
431 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
432 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
434 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
436 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
437 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
440 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
442 if (status & rxmask) {
443 /* Check for high priority Rx first */
444 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
445 (status & ATH9K_INT_RXHP))
446 ath_rx_tasklet(sc, 0, true);
448 ath_rx_tasklet(sc, 0, false);
451 if (status & ATH9K_INT_TX) {
452 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
454 * For EDMA chips, TX completion is enabled for the
455 * beacon queue, so if a beacon has been transmitted
456 * successfully after a GTT interrupt, the GTT counter
457 * gets reset to zero here.
461 ath_tx_edma_tasklet(sc);
466 wake_up(&sc->tx_wait);
469 if (status & ATH9K_INT_GENTIMER)
470 ath_gen_timer_isr(sc->sc_ah);
472 ath9k_btcoex_handle_interrupt(sc, status);
474 /* re-enable hardware interrupt */
475 ath9k_hw_enable_interrupts(ah);
477 spin_unlock(&sc->sc_pcu_lock);
478 ath9k_ps_restore(sc);
481 irqreturn_t ath_isr(int irq, void *dev)
483 #define SCHED_INTR ( \
485 ATH9K_INT_BB_WATCHDOG | \
496 ATH9K_INT_GENTIMER | \
499 struct ath_softc *sc = dev;
500 struct ath_hw *ah = sc->sc_ah;
501 struct ath_common *common = ath9k_hw_common(ah);
502 enum ath9k_int status;
507 * The hardware is not ready/present, don't
508 * touch anything. Note this can happen early
509 * on if the IRQ is shared.
511 if (!ah || test_bit(ATH_OP_INVALID, &common->op_flags))
514 /* shared irq, not for us */
516 if (!ath9k_hw_intrpend(ah))
519 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
520 ath9k_hw_kill_interrupts(ah);
525 * Figure out the reason(s) for the interrupt. Note
526 * that the hal returns a pseudo-ISR that may include
527 * bits we haven't explicitly enabled so we mask the
528 * value to insure we only process bits we requested.
530 ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
531 ath9k_debug_sync_cause(sc, sync_cause);
532 status &= ah->imask; /* discard unasked-for bits */
535 * If there are no status bits set, then this interrupt was not
536 * for me (should have been caught above).
541 /* Cache the status */
542 sc->intrstatus = status;
544 if (status & SCHED_INTR)
548 * If a FATAL or RXORN interrupt is received, we have to reset the
551 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
552 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
555 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
556 (status & ATH9K_INT_BB_WATCHDOG))
559 #ifdef CONFIG_ATH9K_WOW
560 if (status & ATH9K_INT_BMISS) {
561 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
562 atomic_inc(&sc->wow_got_bmiss_intr);
563 atomic_dec(&sc->wow_sleep_proc_intr);
568 if (status & ATH9K_INT_SWBA)
569 tasklet_schedule(&sc->bcon_tasklet);
571 if (status & ATH9K_INT_TXURN)
572 ath9k_hw_updatetxtriglevel(ah, true);
574 if (status & ATH9K_INT_RXEOL) {
575 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
576 ath9k_hw_set_interrupts(ah);
579 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
580 if (status & ATH9K_INT_TIM_TIMER) {
581 if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
583 /* Clear RxAbort bit so that we can
585 ath9k_setpower(sc, ATH9K_PM_AWAKE);
586 spin_lock(&sc->sc_pm_lock);
587 ath9k_hw_setrxabort(sc->sc_ah, 0);
588 sc->ps_flags |= PS_WAIT_FOR_BEACON;
589 spin_unlock(&sc->sc_pm_lock);
594 ath_debug_stat_interrupt(sc, status);
597 /* turn off every interrupt */
598 ath9k_hw_disable_interrupts(ah);
599 tasklet_schedule(&sc->intr_tq);
608 * This function is called when a HW reset cannot be deferred
609 * and has to be immediate.
611 int ath_reset(struct ath_softc *sc, struct ath9k_channel *hchan)
613 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
616 set_bit(ATH_OP_HW_RESET, &common->op_flags);
619 r = ath_reset_internal(sc, hchan);
620 ath9k_ps_restore(sc);
626 * When a HW reset can be deferred, it is added to the
627 * hw_reset_work workqueue, but we set ATH_OP_HW_RESET before
630 void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
632 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
633 #ifdef CONFIG_ATH9K_DEBUGFS
634 RESET_STAT_INC(sc, type);
636 set_bit(ATH_OP_HW_RESET, &common->op_flags);
637 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
640 void ath_reset_work(struct work_struct *work)
642 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
645 ath_reset_internal(sc, NULL);
646 ath9k_ps_restore(sc);
649 /**********************/
650 /* mac80211 callbacks */
651 /**********************/
653 static int ath9k_start(struct ieee80211_hw *hw)
655 struct ath_softc *sc = hw->priv;
656 struct ath_hw *ah = sc->sc_ah;
657 struct ath_common *common = ath9k_hw_common(ah);
658 struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan;
659 struct ath_chanctx *ctx = sc->cur_chan;
660 struct ath9k_channel *init_channel;
663 ath_dbg(common, CONFIG,
664 "Starting driver with initial channel: %d MHz\n",
665 curchan->center_freq);
668 mutex_lock(&sc->mutex);
670 init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
671 sc->cur_chandef = hw->conf.chandef;
673 /* Reset SERDES registers */
674 ath9k_hw_configpcipowersave(ah, false);
677 * The basic interface to setting the hardware in a good
678 * state is ``reset''. On return the hardware is known to
679 * be powered up and with interrupts disabled. This must
680 * be followed by initialization of the appropriate bits
681 * and then setup of the interrupt mask.
683 spin_lock_bh(&sc->sc_pcu_lock);
685 atomic_set(&ah->intr_ref_cnt, -1);
687 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
690 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
691 r, curchan->center_freq);
692 ah->reset_power_on = false;
695 /* Setup our intr mask. */
696 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
697 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
700 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
701 ah->imask |= ATH9K_INT_RXHP |
704 ah->imask |= ATH9K_INT_RX;
706 if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
707 ah->imask |= ATH9K_INT_BB_WATCHDOG;
710 * Enable GTT interrupts only for AR9003/AR9004 chips
713 if (AR_SREV_9300_20_OR_LATER(ah))
714 ah->imask |= ATH9K_INT_GTT;
716 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
717 ah->imask |= ATH9K_INT_CST;
721 clear_bit(ATH_OP_INVALID, &common->op_flags);
722 sc->sc_ah->is_monitoring = false;
724 if (!ath_complete_reset(sc, false))
725 ah->reset_power_on = false;
727 if (ah->led_pin >= 0) {
728 ath9k_hw_cfg_output(ah, ah->led_pin,
729 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
730 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
734 * Reset key cache to sane defaults (all entries cleared) instead of
735 * semi-random values after suspend/resume.
737 ath9k_cmn_init_crypto(sc->sc_ah);
739 ath9k_hw_reset_tsf(ah);
741 spin_unlock_bh(&sc->sc_pcu_lock);
743 mutex_unlock(&sc->mutex);
745 ath9k_ps_restore(sc);
750 static void ath9k_tx(struct ieee80211_hw *hw,
751 struct ieee80211_tx_control *control,
754 struct ath_softc *sc = hw->priv;
755 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
756 struct ath_tx_control txctl;
757 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
760 if (sc->ps_enabled) {
762 * mac80211 does not set PM field for normal data frames, so we
763 * need to update that based on the current PS mode.
765 if (ieee80211_is_data(hdr->frame_control) &&
766 !ieee80211_is_nullfunc(hdr->frame_control) &&
767 !ieee80211_has_pm(hdr->frame_control)) {
769 "Add PM=1 for a TX frame while in PS mode\n");
770 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
774 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
776 * We are using PS-Poll and mac80211 can request TX while in
777 * power save mode. Need to wake up hardware for the TX to be
778 * completed and if needed, also for RX of buffered frames.
781 spin_lock_irqsave(&sc->sc_pm_lock, flags);
782 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
783 ath9k_hw_setrxabort(sc->sc_ah, 0);
784 if (ieee80211_is_pspoll(hdr->frame_control)) {
786 "Sending PS-Poll to pick a buffered frame\n");
787 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
789 ath_dbg(common, PS, "Wake up to complete TX\n");
790 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
793 * The actual restore operation will happen only after
794 * the ps_flags bit is cleared. We are just dropping
795 * the ps_usecount here.
797 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
798 ath9k_ps_restore(sc);
802 * Cannot tx while the hardware is in full sleep, it first needs a full
803 * chip reset to recover from that
805 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
806 ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
810 memset(&txctl, 0, sizeof(struct ath_tx_control));
811 txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
812 txctl.sta = control->sta;
814 ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
816 if (ath_tx_start(hw, skb, &txctl) != 0) {
817 ath_dbg(common, XMIT, "TX failed\n");
818 TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
824 ieee80211_free_txskb(hw, skb);
827 static void ath9k_stop(struct ieee80211_hw *hw)
829 struct ath_softc *sc = hw->priv;
830 struct ath_hw *ah = sc->sc_ah;
831 struct ath_common *common = ath9k_hw_common(ah);
834 ath9k_deinit_channel_context(sc);
836 mutex_lock(&sc->mutex);
840 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
841 ath_dbg(common, ANY, "Device not present\n");
842 mutex_unlock(&sc->mutex);
846 /* Ensure HW is awake when we try to shut it down. */
849 spin_lock_bh(&sc->sc_pcu_lock);
851 /* prevent tasklets to enable interrupts once we disable them */
852 ah->imask &= ~ATH9K_INT_GLOBAL;
854 /* make sure h/w will not generate any interrupt
855 * before setting the invalid flag. */
856 ath9k_hw_disable_interrupts(ah);
858 spin_unlock_bh(&sc->sc_pcu_lock);
860 /* we can now sync irq and kill any running tasklets, since we already
861 * disabled interrupts and not holding a spin lock */
862 synchronize_irq(sc->irq);
863 tasklet_kill(&sc->intr_tq);
864 tasklet_kill(&sc->bcon_tasklet);
866 prev_idle = sc->ps_idle;
869 spin_lock_bh(&sc->sc_pcu_lock);
871 if (ah->led_pin >= 0) {
872 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
873 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
876 ath_prepare_reset(sc);
879 dev_kfree_skb_any(sc->rx.frag);
884 ah->curchan = ath9k_cmn_get_channel(hw, ah,
885 &sc->cur_chan->chandef);
887 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
888 ath9k_hw_phy_disable(ah);
890 ath9k_hw_configpcipowersave(ah, true);
892 spin_unlock_bh(&sc->sc_pcu_lock);
894 ath9k_ps_restore(sc);
896 set_bit(ATH_OP_INVALID, &common->op_flags);
897 sc->ps_idle = prev_idle;
899 mutex_unlock(&sc->mutex);
901 ath_dbg(common, CONFIG, "Driver halt\n");
904 static bool ath9k_uses_beacons(int type)
907 case NL80211_IFTYPE_AP:
908 case NL80211_IFTYPE_ADHOC:
909 case NL80211_IFTYPE_MESH_POINT:
916 static void ath9k_vif_iter(struct ath9k_vif_iter_data *iter_data,
917 u8 *mac, struct ieee80211_vif *vif)
919 struct ath_vif *avp = (struct ath_vif *)vif->drv_priv;
922 if (iter_data->has_hw_macaddr) {
923 for (i = 0; i < ETH_ALEN; i++)
924 iter_data->mask[i] &=
925 ~(iter_data->hw_macaddr[i] ^ mac[i]);
927 memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
928 iter_data->has_hw_macaddr = true;
931 if (!vif->bss_conf.use_short_slot)
932 iter_data->slottime = ATH9K_SLOT_TIME_20;
935 case NL80211_IFTYPE_AP:
938 case NL80211_IFTYPE_STATION:
939 iter_data->nstations++;
940 if (avp->assoc && !iter_data->primary_sta)
941 iter_data->primary_sta = vif;
943 case NL80211_IFTYPE_ADHOC:
944 iter_data->nadhocs++;
945 if (vif->bss_conf.enable_beacon)
946 iter_data->beacons = true;
948 case NL80211_IFTYPE_MESH_POINT:
949 iter_data->nmeshes++;
950 if (vif->bss_conf.enable_beacon)
951 iter_data->beacons = true;
953 case NL80211_IFTYPE_WDS:
961 static void ath9k_update_bssid_mask(struct ath_softc *sc,
962 struct ath_chanctx *ctx,
963 struct ath9k_vif_iter_data *iter_data)
965 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
969 if (!ath9k_is_chanctx_enabled())
972 list_for_each_entry(avp, &ctx->vifs, list) {
973 if (ctx->nvifs_assigned != 1)
976 if (!avp->vif->p2p || !iter_data->has_hw_macaddr)
979 ether_addr_copy(common->curbssid, avp->bssid);
981 /* perm_addr will be used as the p2p device address. */
982 for (i = 0; i < ETH_ALEN; i++)
983 iter_data->mask[i] &=
984 ~(iter_data->hw_macaddr[i] ^
985 sc->hw->wiphy->perm_addr[i]);
989 /* Called with sc->mutex held. */
990 void ath9k_calculate_iter_data(struct ath_softc *sc,
991 struct ath_chanctx *ctx,
992 struct ath9k_vif_iter_data *iter_data)
997 * Pick the MAC address of the first interface as the new hardware
998 * MAC address. The hardware will use it together with the BSSID mask
999 * when matching addresses.
1001 memset(iter_data, 0, sizeof(*iter_data));
1002 memset(&iter_data->mask, 0xff, ETH_ALEN);
1003 iter_data->slottime = ATH9K_SLOT_TIME_9;
1005 list_for_each_entry(avp, &ctx->vifs, list)
1006 ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif);
1008 ath9k_update_bssid_mask(sc, ctx, iter_data);
1011 static void ath9k_set_assoc_state(struct ath_softc *sc,
1012 struct ieee80211_vif *vif, bool changed)
1014 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1015 struct ath_vif *avp = (struct ath_vif *)vif->drv_priv;
1016 unsigned long flags;
1018 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1020 ether_addr_copy(common->curbssid, avp->bssid);
1021 common->curaid = avp->aid;
1022 ath9k_hw_write_associd(sc->sc_ah);
1025 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
1026 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
1028 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1029 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
1030 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1033 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1034 ath9k_mci_update_wlan_channels(sc, false);
1036 ath_dbg(common, CONFIG,
1037 "Primary Station interface: %pM, BSSID: %pM\n",
1038 vif->addr, common->curbssid);
1041 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
1042 static void ath9k_set_offchannel_state(struct ath_softc *sc)
1044 struct ath_hw *ah = sc->sc_ah;
1045 struct ath_common *common = ath9k_hw_common(ah);
1046 struct ieee80211_vif *vif = NULL;
1048 ath9k_ps_wakeup(sc);
1050 if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START)
1051 vif = sc->offchannel.scan_vif;
1053 vif = sc->offchannel.roc_vif;
1058 eth_zero_addr(common->curbssid);
1059 eth_broadcast_addr(common->bssidmask);
1060 memcpy(common->macaddr, vif->addr, ETH_ALEN);
1062 ah->opmode = vif->type;
1063 ah->imask &= ~ATH9K_INT_SWBA;
1064 ah->imask &= ~ATH9K_INT_TSFOOR;
1065 ah->slottime = ATH9K_SLOT_TIME_9;
1067 ath_hw_setbssidmask(common);
1068 ath9k_hw_setopmode(ah);
1069 ath9k_hw_write_associd(sc->sc_ah);
1070 ath9k_hw_set_interrupts(ah);
1071 ath9k_hw_init_global_settings(ah);
1074 ath9k_ps_restore(sc);
1078 /* Called with sc->mutex held. */
1079 void ath9k_calculate_summary_state(struct ath_softc *sc,
1080 struct ath_chanctx *ctx)
1082 struct ath_hw *ah = sc->sc_ah;
1083 struct ath_common *common = ath9k_hw_common(ah);
1084 struct ath9k_vif_iter_data iter_data;
1085 struct ath_beacon_config *cur_conf;
1087 ath_chanctx_check_active(sc, ctx);
1089 if (ctx != sc->cur_chan)
1092 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
1093 if (ctx == &sc->offchannel.chan)
1094 return ath9k_set_offchannel_state(sc);
1097 ath9k_ps_wakeup(sc);
1098 ath9k_calculate_iter_data(sc, ctx, &iter_data);
1100 if (iter_data.has_hw_macaddr)
1101 memcpy(common->macaddr, iter_data.hw_macaddr, ETH_ALEN);
1103 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
1104 ath_hw_setbssidmask(common);
1106 if (iter_data.naps > 0) {
1107 cur_conf = &ctx->beacon;
1108 ath9k_hw_set_tsfadjust(ah, true);
1109 ah->opmode = NL80211_IFTYPE_AP;
1110 if (cur_conf->enable_beacon)
1111 iter_data.beacons = true;
1113 ath9k_hw_set_tsfadjust(ah, false);
1115 if (iter_data.nmeshes)
1116 ah->opmode = NL80211_IFTYPE_MESH_POINT;
1117 else if (iter_data.nwds)
1118 ah->opmode = NL80211_IFTYPE_AP;
1119 else if (iter_data.nadhocs)
1120 ah->opmode = NL80211_IFTYPE_ADHOC;
1122 ah->opmode = NL80211_IFTYPE_STATION;
1125 ath9k_hw_setopmode(ah);
1127 ctx->switch_after_beacon = false;
1128 if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
1129 ah->imask |= ATH9K_INT_TSFOOR;
1131 ah->imask &= ~ATH9K_INT_TSFOOR;
1132 if (iter_data.naps == 1 && iter_data.beacons)
1133 ctx->switch_after_beacon = true;
1136 ah->imask &= ~ATH9K_INT_SWBA;
1137 if (ah->opmode == NL80211_IFTYPE_STATION) {
1138 bool changed = (iter_data.primary_sta != ctx->primary_sta);
1140 if (iter_data.primary_sta) {
1141 iter_data.beacons = true;
1142 ath9k_set_assoc_state(sc, iter_data.primary_sta,
1144 ctx->primary_sta = iter_data.primary_sta;
1146 ctx->primary_sta = NULL;
1147 memset(common->curbssid, 0, ETH_ALEN);
1149 ath9k_hw_write_associd(sc->sc_ah);
1150 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1151 ath9k_mci_update_wlan_channels(sc, true);
1153 } else if (iter_data.beacons) {
1154 ah->imask |= ATH9K_INT_SWBA;
1156 ath9k_hw_set_interrupts(ah);
1158 if (iter_data.beacons)
1159 set_bit(ATH_OP_BEACONS, &common->op_flags);
1161 clear_bit(ATH_OP_BEACONS, &common->op_flags);
1163 if (ah->slottime != iter_data.slottime) {
1164 ah->slottime = iter_data.slottime;
1165 ath9k_hw_init_global_settings(ah);
1168 if (iter_data.primary_sta)
1169 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1171 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1173 ath_dbg(common, CONFIG,
1174 "macaddr: %pM, bssid: %pM, bssidmask: %pM\n",
1175 common->macaddr, common->curbssid, common->bssidmask);
1177 ath9k_ps_restore(sc);
1180 static void ath9k_assign_hw_queues(struct ieee80211_hw *hw,
1181 struct ieee80211_vif *vif)
1185 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1186 vif->hw_queue[i] = i;
1188 if (vif->type == NL80211_IFTYPE_AP)
1189 vif->cab_queue = hw->queues - 2;
1191 vif->cab_queue = IEEE80211_INVAL_HW_QUEUE;
1194 static int ath9k_add_interface(struct ieee80211_hw *hw,
1195 struct ieee80211_vif *vif)
1197 struct ath_softc *sc = hw->priv;
1198 struct ath_hw *ah = sc->sc_ah;
1199 struct ath_common *common = ath9k_hw_common(ah);
1200 struct ath_vif *avp = (void *)vif->drv_priv;
1201 struct ath_node *an = &avp->mcast_node;
1203 mutex_lock(&sc->mutex);
1205 if (config_enabled(CONFIG_ATH9K_TX99)) {
1206 if (sc->cur_chan->nvifs >= 1) {
1207 mutex_unlock(&sc->mutex);
1213 ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
1214 sc->cur_chan->nvifs++;
1216 if (ath9k_uses_beacons(vif->type))
1217 ath9k_beacon_assign_slot(sc, vif);
1220 if (!ath9k_is_chanctx_enabled()) {
1221 avp->chanctx = sc->cur_chan;
1222 list_add_tail(&avp->list, &avp->chanctx->vifs);
1225 ath9k_assign_hw_queues(hw, vif);
1230 an->no_ps_filter = true;
1231 ath_tx_node_init(sc, an);
1233 mutex_unlock(&sc->mutex);
1237 static int ath9k_change_interface(struct ieee80211_hw *hw,
1238 struct ieee80211_vif *vif,
1239 enum nl80211_iftype new_type,
1242 struct ath_softc *sc = hw->priv;
1243 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1244 struct ath_vif *avp = (void *)vif->drv_priv;
1246 mutex_lock(&sc->mutex);
1248 if (config_enabled(CONFIG_ATH9K_TX99)) {
1249 mutex_unlock(&sc->mutex);
1253 ath_dbg(common, CONFIG, "Change Interface\n");
1255 if (ath9k_uses_beacons(vif->type))
1256 ath9k_beacon_remove_slot(sc, vif);
1258 vif->type = new_type;
1261 if (ath9k_uses_beacons(vif->type))
1262 ath9k_beacon_assign_slot(sc, vif);
1264 ath9k_assign_hw_queues(hw, vif);
1265 ath9k_calculate_summary_state(sc, avp->chanctx);
1267 mutex_unlock(&sc->mutex);
1271 static void ath9k_remove_interface(struct ieee80211_hw *hw,
1272 struct ieee80211_vif *vif)
1274 struct ath_softc *sc = hw->priv;
1275 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1276 struct ath_vif *avp = (void *)vif->drv_priv;
1278 ath_dbg(common, CONFIG, "Detach Interface\n");
1280 mutex_lock(&sc->mutex);
1282 ath9k_p2p_remove_vif(sc, vif);
1284 sc->cur_chan->nvifs--;
1285 sc->tx99_vif = NULL;
1286 if (!ath9k_is_chanctx_enabled())
1287 list_del(&avp->list);
1289 if (ath9k_uses_beacons(vif->type))
1290 ath9k_beacon_remove_slot(sc, vif);
1292 ath_tx_node_cleanup(sc, &avp->mcast_node);
1294 mutex_unlock(&sc->mutex);
1297 static void ath9k_enable_ps(struct ath_softc *sc)
1299 struct ath_hw *ah = sc->sc_ah;
1300 struct ath_common *common = ath9k_hw_common(ah);
1302 if (config_enabled(CONFIG_ATH9K_TX99))
1305 sc->ps_enabled = true;
1306 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1307 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1308 ah->imask |= ATH9K_INT_TIM_TIMER;
1309 ath9k_hw_set_interrupts(ah);
1311 ath9k_hw_setrxabort(ah, 1);
1313 ath_dbg(common, PS, "PowerSave enabled\n");
1316 static void ath9k_disable_ps(struct ath_softc *sc)
1318 struct ath_hw *ah = sc->sc_ah;
1319 struct ath_common *common = ath9k_hw_common(ah);
1321 if (config_enabled(CONFIG_ATH9K_TX99))
1324 sc->ps_enabled = false;
1325 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1326 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1327 ath9k_hw_setrxabort(ah, 0);
1328 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1330 PS_WAIT_FOR_PSPOLL_DATA |
1331 PS_WAIT_FOR_TX_ACK);
1332 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1333 ah->imask &= ~ATH9K_INT_TIM_TIMER;
1334 ath9k_hw_set_interrupts(ah);
1337 ath_dbg(common, PS, "PowerSave disabled\n");
1340 void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
1342 struct ath_softc *sc = hw->priv;
1343 struct ath_hw *ah = sc->sc_ah;
1344 struct ath_common *common = ath9k_hw_common(ah);
1347 if (config_enabled(CONFIG_ATH9K_TX99))
1350 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1351 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1355 ath9k_ps_wakeup(sc);
1356 rxfilter = ath9k_hw_getrxfilter(ah);
1357 ath9k_hw_setrxfilter(ah, rxfilter |
1358 ATH9K_RX_FILTER_PHYRADAR |
1359 ATH9K_RX_FILTER_PHYERR);
1361 /* TODO: usually this should not be neccesary, but for some reason
1362 * (or in some mode?) the trigger must be called after the
1363 * configuration, otherwise the register will have its values reset
1364 * (on my ar9220 to value 0x01002310)
1366 ath9k_spectral_scan_config(hw, sc->spectral_mode);
1367 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
1368 ath9k_ps_restore(sc);
1371 int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
1372 enum spectral_mode spectral_mode)
1374 struct ath_softc *sc = hw->priv;
1375 struct ath_hw *ah = sc->sc_ah;
1376 struct ath_common *common = ath9k_hw_common(ah);
1378 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1379 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1383 switch (spectral_mode) {
1384 case SPECTRAL_DISABLED:
1385 sc->spec_config.enabled = 0;
1387 case SPECTRAL_BACKGROUND:
1388 /* send endless samples.
1389 * TODO: is this really useful for "background"?
1391 sc->spec_config.endless = 1;
1392 sc->spec_config.enabled = 1;
1394 case SPECTRAL_CHANSCAN:
1395 case SPECTRAL_MANUAL:
1396 sc->spec_config.endless = 0;
1397 sc->spec_config.enabled = 1;
1403 ath9k_ps_wakeup(sc);
1404 ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
1405 ath9k_ps_restore(sc);
1407 sc->spectral_mode = spectral_mode;
1412 static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1414 struct ath_softc *sc = hw->priv;
1415 struct ath_hw *ah = sc->sc_ah;
1416 struct ath_common *common = ath9k_hw_common(ah);
1417 struct ieee80211_conf *conf = &hw->conf;
1418 struct ath_chanctx *ctx = sc->cur_chan;
1420 ath9k_ps_wakeup(sc);
1421 mutex_lock(&sc->mutex);
1423 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1424 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1426 ath_cancel_work(sc);
1427 ath9k_stop_btcoex(sc);
1429 ath9k_start_btcoex(sc);
1431 * The chip needs a reset to properly wake up from
1434 ath_chanctx_set_channel(sc, ctx, &ctx->chandef);
1439 * We just prepare to enable PS. We have to wait until our AP has
1440 * ACK'd our null data frame to disable RX otherwise we'll ignore
1441 * those ACKs and end up retransmitting the same null data frames.
1442 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1444 if (changed & IEEE80211_CONF_CHANGE_PS) {
1445 unsigned long flags;
1446 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1447 if (conf->flags & IEEE80211_CONF_PS)
1448 ath9k_enable_ps(sc);
1450 ath9k_disable_ps(sc);
1451 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1454 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1455 if (conf->flags & IEEE80211_CONF_MONITOR) {
1456 ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
1457 sc->sc_ah->is_monitoring = true;
1459 ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
1460 sc->sc_ah->is_monitoring = false;
1464 if (!ath9k_is_chanctx_enabled() && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
1465 ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
1466 ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef);
1469 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1470 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
1471 sc->cur_chan->txpower = 2 * conf->power_level;
1472 ath9k_cmn_update_txpow(ah, sc->curtxpow,
1473 sc->cur_chan->txpower, &sc->curtxpow);
1476 mutex_unlock(&sc->mutex);
1477 ath9k_ps_restore(sc);
1482 #define SUPPORTED_FILTERS \
1483 (FIF_PROMISC_IN_BSS | \
1488 FIF_BCN_PRBRESP_PROMISC | \
1492 /* FIXME: sc->sc_full_reset ? */
1493 static void ath9k_configure_filter(struct ieee80211_hw *hw,
1494 unsigned int changed_flags,
1495 unsigned int *total_flags,
1498 struct ath_softc *sc = hw->priv;
1501 changed_flags &= SUPPORTED_FILTERS;
1502 *total_flags &= SUPPORTED_FILTERS;
1504 spin_lock_bh(&sc->chan_lock);
1505 sc->cur_chan->rxfilter = *total_flags;
1506 spin_unlock_bh(&sc->chan_lock);
1508 ath9k_ps_wakeup(sc);
1509 rfilt = ath_calcrxfilter(sc);
1510 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
1511 ath9k_ps_restore(sc);
1513 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
1517 static int ath9k_sta_add(struct ieee80211_hw *hw,
1518 struct ieee80211_vif *vif,
1519 struct ieee80211_sta *sta)
1521 struct ath_softc *sc = hw->priv;
1522 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1523 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1524 struct ieee80211_key_conf ps_key = { };
1527 ath_node_attach(sc, sta, vif);
1529 if (vif->type != NL80211_IFTYPE_AP &&
1530 vif->type != NL80211_IFTYPE_AP_VLAN)
1533 key = ath_key_config(common, vif, sta, &ps_key);
1536 an->key_idx[0] = key;
1542 static void ath9k_del_ps_key(struct ath_softc *sc,
1543 struct ieee80211_vif *vif,
1544 struct ieee80211_sta *sta)
1546 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1547 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1548 struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
1553 ath_key_delete(common, &ps_key);
1558 static int ath9k_sta_remove(struct ieee80211_hw *hw,
1559 struct ieee80211_vif *vif,
1560 struct ieee80211_sta *sta)
1562 struct ath_softc *sc = hw->priv;
1564 ath9k_del_ps_key(sc, vif, sta);
1565 ath_node_detach(sc, sta);
1570 static int ath9k_sta_state(struct ieee80211_hw *hw,
1571 struct ieee80211_vif *vif,
1572 struct ieee80211_sta *sta,
1573 enum ieee80211_sta_state old_state,
1574 enum ieee80211_sta_state new_state)
1576 struct ath_softc *sc = hw->priv;
1577 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1580 if (old_state == IEEE80211_STA_AUTH &&
1581 new_state == IEEE80211_STA_ASSOC) {
1582 ret = ath9k_sta_add(hw, vif, sta);
1583 ath_dbg(common, CONFIG,
1584 "Add station: %pM\n", sta->addr);
1585 } else if (old_state == IEEE80211_STA_ASSOC &&
1586 new_state == IEEE80211_STA_AUTH) {
1587 ret = ath9k_sta_remove(hw, vif, sta);
1588 ath_dbg(common, CONFIG,
1589 "Remove station: %pM\n", sta->addr);
1592 if (ath9k_is_chanctx_enabled()) {
1593 if (vif->type == NL80211_IFTYPE_STATION) {
1594 if (old_state == IEEE80211_STA_ASSOC &&
1595 new_state == IEEE80211_STA_AUTHORIZED)
1596 ath_chanctx_event(sc, vif,
1597 ATH_CHANCTX_EVENT_AUTHORIZED);
1604 static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
1605 struct ath_node *an,
1610 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1611 if (!an->key_idx[i])
1613 ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
1617 static void ath9k_sta_notify(struct ieee80211_hw *hw,
1618 struct ieee80211_vif *vif,
1619 enum sta_notify_cmd cmd,
1620 struct ieee80211_sta *sta)
1622 struct ath_softc *sc = hw->priv;
1623 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1626 case STA_NOTIFY_SLEEP:
1627 an->sleeping = true;
1628 ath_tx_aggr_sleep(sta, sc, an);
1629 ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
1631 case STA_NOTIFY_AWAKE:
1632 ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
1633 an->sleeping = false;
1634 ath_tx_aggr_wakeup(sc, an);
1639 static int ath9k_conf_tx(struct ieee80211_hw *hw,
1640 struct ieee80211_vif *vif, u16 queue,
1641 const struct ieee80211_tx_queue_params *params)
1643 struct ath_softc *sc = hw->priv;
1644 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1645 struct ath_txq *txq;
1646 struct ath9k_tx_queue_info qi;
1649 if (queue >= IEEE80211_NUM_ACS)
1652 txq = sc->tx.txq_map[queue];
1654 ath9k_ps_wakeup(sc);
1655 mutex_lock(&sc->mutex);
1657 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1659 qi.tqi_aifs = params->aifs;
1660 qi.tqi_cwmin = params->cw_min;
1661 qi.tqi_cwmax = params->cw_max;
1662 qi.tqi_burstTime = params->txop * 32;
1664 ath_dbg(common, CONFIG,
1665 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1666 queue, txq->axq_qnum, params->aifs, params->cw_min,
1667 params->cw_max, params->txop);
1669 ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
1670 ret = ath_txq_update(sc, txq->axq_qnum, &qi);
1672 ath_err(common, "TXQ Update failed\n");
1674 mutex_unlock(&sc->mutex);
1675 ath9k_ps_restore(sc);
1680 static int ath9k_set_key(struct ieee80211_hw *hw,
1681 enum set_key_cmd cmd,
1682 struct ieee80211_vif *vif,
1683 struct ieee80211_sta *sta,
1684 struct ieee80211_key_conf *key)
1686 struct ath_softc *sc = hw->priv;
1687 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1688 struct ath_node *an = NULL;
1691 if (ath9k_modparam_nohwcrypt)
1694 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1695 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1696 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1697 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1698 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1700 * For now, disable hw crypto for the RSN IBSS group keys. This
1701 * could be optimized in the future to use a modified key cache
1702 * design to support per-STA RX GTK, but until that gets
1703 * implemented, use of software crypto for group addressed
1704 * frames is a acceptable to allow RSN IBSS to be used.
1709 mutex_lock(&sc->mutex);
1710 ath9k_ps_wakeup(sc);
1711 ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
1713 an = (struct ath_node *)sta->drv_priv;
1718 ath9k_del_ps_key(sc, vif, sta);
1720 key->hw_key_idx = 0;
1721 ret = ath_key_config(common, vif, sta, key);
1723 key->hw_key_idx = ret;
1724 /* push IV and Michael MIC generation to stack */
1725 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1726 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1727 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1728 if (sc->sc_ah->sw_mgmt_crypto &&
1729 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1730 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1733 if (an && key->hw_key_idx) {
1734 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1737 an->key_idx[i] = key->hw_key_idx;
1740 WARN_ON(i == ARRAY_SIZE(an->key_idx));
1744 ath_key_delete(common, key);
1746 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1747 if (an->key_idx[i] != key->hw_key_idx)
1753 key->hw_key_idx = 0;
1759 ath9k_ps_restore(sc);
1760 mutex_unlock(&sc->mutex);
1765 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1766 struct ieee80211_vif *vif,
1767 struct ieee80211_bss_conf *bss_conf,
1771 (BSS_CHANGED_ASSOC | \
1772 BSS_CHANGED_IBSS | \
1773 BSS_CHANGED_BEACON_ENABLED)
1775 struct ath_softc *sc = hw->priv;
1776 struct ath_hw *ah = sc->sc_ah;
1777 struct ath_common *common = ath9k_hw_common(ah);
1778 struct ath_vif *avp = (void *)vif->drv_priv;
1781 ath9k_ps_wakeup(sc);
1782 mutex_lock(&sc->mutex);
1784 if (changed & BSS_CHANGED_ASSOC) {
1785 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
1786 bss_conf->bssid, bss_conf->assoc);
1788 memcpy(avp->bssid, bss_conf->bssid, ETH_ALEN);
1789 avp->aid = bss_conf->aid;
1790 avp->assoc = bss_conf->assoc;
1792 ath9k_calculate_summary_state(sc, avp->chanctx);
1795 if (changed & BSS_CHANGED_IBSS) {
1796 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1797 common->curaid = bss_conf->aid;
1798 ath9k_hw_write_associd(sc->sc_ah);
1801 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
1802 (changed & BSS_CHANGED_BEACON_INT) ||
1803 (changed & BSS_CHANGED_BEACON_INFO)) {
1804 ath9k_beacon_config(sc, vif, changed);
1805 if (changed & BSS_CHANGED_BEACON_ENABLED)
1806 ath9k_calculate_summary_state(sc, avp->chanctx);
1809 if ((avp->chanctx == sc->cur_chan) &&
1810 (changed & BSS_CHANGED_ERP_SLOT)) {
1811 if (bss_conf->use_short_slot)
1815 if (vif->type == NL80211_IFTYPE_AP) {
1817 * Defer update, so that connected stations can adjust
1818 * their settings at the same time.
1819 * See beacon.c for more details
1821 sc->beacon.slottime = slottime;
1822 sc->beacon.updateslot = UPDATE;
1824 ah->slottime = slottime;
1825 ath9k_hw_init_global_settings(ah);
1829 if (changed & BSS_CHANGED_P2P_PS)
1830 ath9k_p2p_bss_info_changed(sc, vif);
1832 if (changed & CHECK_ANI)
1835 mutex_unlock(&sc->mutex);
1836 ath9k_ps_restore(sc);
1841 static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1843 struct ath_softc *sc = hw->priv;
1846 mutex_lock(&sc->mutex);
1847 ath9k_ps_wakeup(sc);
1848 tsf = ath9k_hw_gettsf64(sc->sc_ah);
1849 ath9k_ps_restore(sc);
1850 mutex_unlock(&sc->mutex);
1855 static void ath9k_set_tsf(struct ieee80211_hw *hw,
1856 struct ieee80211_vif *vif,
1859 struct ath_softc *sc = hw->priv;
1861 mutex_lock(&sc->mutex);
1862 ath9k_ps_wakeup(sc);
1863 ath9k_hw_settsf64(sc->sc_ah, tsf);
1864 ath9k_ps_restore(sc);
1865 mutex_unlock(&sc->mutex);
1868 static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1870 struct ath_softc *sc = hw->priv;
1872 mutex_lock(&sc->mutex);
1874 ath9k_ps_wakeup(sc);
1875 ath9k_hw_reset_tsf(sc->sc_ah);
1876 ath9k_ps_restore(sc);
1878 mutex_unlock(&sc->mutex);
1881 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1882 struct ieee80211_vif *vif,
1883 enum ieee80211_ampdu_mlme_action action,
1884 struct ieee80211_sta *sta,
1885 u16 tid, u16 *ssn, u8 buf_size)
1887 struct ath_softc *sc = hw->priv;
1891 mutex_lock(&sc->mutex);
1894 case IEEE80211_AMPDU_RX_START:
1896 case IEEE80211_AMPDU_RX_STOP:
1898 case IEEE80211_AMPDU_TX_START:
1899 ath9k_ps_wakeup(sc);
1900 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1902 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1903 ath9k_ps_restore(sc);
1905 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1906 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1908 case IEEE80211_AMPDU_TX_STOP_CONT:
1909 ath9k_ps_wakeup(sc);
1910 ath_tx_aggr_stop(sc, sta, tid);
1912 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1913 ath9k_ps_restore(sc);
1915 case IEEE80211_AMPDU_TX_OPERATIONAL:
1916 ath9k_ps_wakeup(sc);
1917 ath_tx_aggr_resume(sc, sta, tid);
1918 ath9k_ps_restore(sc);
1921 ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
1924 mutex_unlock(&sc->mutex);
1929 static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
1930 struct survey_info *survey)
1932 struct ath_softc *sc = hw->priv;
1933 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1934 struct ieee80211_supported_band *sband;
1935 struct ieee80211_channel *chan;
1938 if (config_enabled(CONFIG_ATH9K_TX99))
1941 spin_lock_bh(&common->cc_lock);
1943 ath_update_survey_stats(sc);
1945 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
1946 if (sband && idx >= sband->n_channels) {
1947 idx -= sband->n_channels;
1952 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
1954 if (!sband || idx >= sband->n_channels) {
1955 spin_unlock_bh(&common->cc_lock);
1959 chan = &sband->channels[idx];
1960 pos = chan->hw_value;
1961 memcpy(survey, &sc->survey[pos], sizeof(*survey));
1962 survey->channel = chan;
1963 spin_unlock_bh(&common->cc_lock);
1968 static void ath9k_enable_dynack(struct ath_softc *sc)
1970 #ifdef CONFIG_ATH9K_DYNACK
1972 struct ath_hw *ah = sc->sc_ah;
1974 ath_dynack_reset(ah);
1976 ah->dynack.enabled = true;
1977 rfilt = ath_calcrxfilter(sc);
1978 ath9k_hw_setrxfilter(ah, rfilt);
1982 static void ath9k_set_coverage_class(struct ieee80211_hw *hw,
1985 struct ath_softc *sc = hw->priv;
1986 struct ath_hw *ah = sc->sc_ah;
1988 if (config_enabled(CONFIG_ATH9K_TX99))
1991 mutex_lock(&sc->mutex);
1993 if (coverage_class >= 0) {
1994 ah->coverage_class = coverage_class;
1995 if (ah->dynack.enabled) {
1998 ah->dynack.enabled = false;
1999 rfilt = ath_calcrxfilter(sc);
2000 ath9k_hw_setrxfilter(ah, rfilt);
2002 ath9k_ps_wakeup(sc);
2003 ath9k_hw_init_global_settings(ah);
2004 ath9k_ps_restore(sc);
2005 } else if (!ah->dynack.enabled) {
2006 ath9k_enable_dynack(sc);
2009 mutex_unlock(&sc->mutex);
2012 static bool ath9k_has_tx_pending(struct ath_softc *sc,
2017 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2018 if (!ATH_TXQ_SETUP(sc, i))
2021 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i],
2030 static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2031 u32 queues, bool drop)
2033 struct ath_softc *sc = hw->priv;
2035 mutex_lock(&sc->mutex);
2036 __ath9k_flush(hw, queues, drop, true);
2037 mutex_unlock(&sc->mutex);
2040 void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop,
2043 struct ath_softc *sc = hw->priv;
2044 struct ath_hw *ah = sc->sc_ah;
2045 struct ath_common *common = ath9k_hw_common(ah);
2049 cancel_delayed_work_sync(&sc->tx_complete_work);
2051 if (ah->ah_flags & AH_UNPLUGGED) {
2052 ath_dbg(common, ANY, "Device has been unplugged!\n");
2056 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
2057 ath_dbg(common, ANY, "Device not present\n");
2061 spin_lock_bh(&sc->chan_lock);
2062 timeout = sc->cur_chan->flush_timeout;
2063 spin_unlock_bh(&sc->chan_lock);
2065 ath_dbg(common, CHAN_CTX,
2066 "Flush timeout: %d\n", jiffies_to_msecs(timeout));
2068 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc, sw_pending),
2073 ath9k_ps_wakeup(sc);
2074 spin_lock_bh(&sc->sc_pcu_lock);
2075 drain_txq = ath_drain_all_txq(sc);
2076 spin_unlock_bh(&sc->sc_pcu_lock);
2079 ath_reset(sc, NULL);
2081 ath9k_ps_restore(sc);
2084 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
2087 static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
2089 struct ath_softc *sc = hw->priv;
2091 return ath9k_has_tx_pending(sc, true);
2094 static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
2096 struct ath_softc *sc = hw->priv;
2097 struct ath_hw *ah = sc->sc_ah;
2098 struct ieee80211_vif *vif;
2099 struct ath_vif *avp;
2101 struct ath_tx_status ts;
2102 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
2105 vif = sc->beacon.bslot[0];
2109 if (!vif->bss_conf.enable_beacon)
2112 avp = (void *)vif->drv_priv;
2114 if (!sc->beacon.tx_processed && !edma) {
2115 tasklet_disable(&sc->bcon_tasklet);
2118 if (!bf || !bf->bf_mpdu)
2121 status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
2122 if (status == -EINPROGRESS)
2125 sc->beacon.tx_processed = true;
2126 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
2129 tasklet_enable(&sc->bcon_tasklet);
2132 return sc->beacon.tx_last;
2135 static int ath9k_get_stats(struct ieee80211_hw *hw,
2136 struct ieee80211_low_level_stats *stats)
2138 struct ath_softc *sc = hw->priv;
2139 struct ath_hw *ah = sc->sc_ah;
2140 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
2142 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
2143 stats->dot11RTSFailureCount = mib_stats->rts_bad;
2144 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
2145 stats->dot11RTSSuccessCount = mib_stats->rts_good;
2149 static u32 fill_chainmask(u32 cap, u32 new)
2154 for (i = 0; cap && new; i++, cap >>= 1) {
2155 if (!(cap & BIT(0)))
2167 static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
2169 if (AR_SREV_9300_20_OR_LATER(ah))
2172 switch (val & 0x7) {
2178 return (ah->caps.rx_chainmask == 1);
2184 static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2186 struct ath_softc *sc = hw->priv;
2187 struct ath_hw *ah = sc->sc_ah;
2189 if (ah->caps.rx_chainmask != 1)
2192 if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
2195 sc->ant_rx = rx_ant;
2196 sc->ant_tx = tx_ant;
2198 if (ah->caps.rx_chainmask == 1)
2201 /* AR9100 runs into calibration issues if not all rx chains are enabled */
2202 if (AR_SREV_9100(ah))
2203 ah->rxchainmask = 0x7;
2205 ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
2207 ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
2208 ath9k_cmn_reload_chainmask(ah);
2213 static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2215 struct ath_softc *sc = hw->priv;
2217 *tx_ant = sc->ant_tx;
2218 *rx_ant = sc->ant_rx;
2222 static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2224 struct ath_softc *sc = hw->priv;
2225 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2226 set_bit(ATH_OP_SCANNING, &common->op_flags);
2229 static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2231 struct ath_softc *sc = hw->priv;
2232 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2233 clear_bit(ATH_OP_SCANNING, &common->op_flags);
2236 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
2238 static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2239 struct ieee80211_scan_request *hw_req)
2241 struct cfg80211_scan_request *req = &hw_req->req;
2242 struct ath_softc *sc = hw->priv;
2243 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2246 mutex_lock(&sc->mutex);
2248 if (WARN_ON(sc->offchannel.scan_req)) {
2253 ath9k_ps_wakeup(sc);
2254 set_bit(ATH_OP_SCANNING, &common->op_flags);
2255 sc->offchannel.scan_vif = vif;
2256 sc->offchannel.scan_req = req;
2257 sc->offchannel.scan_idx = 0;
2259 ath_dbg(common, CHAN_CTX, "HW scan request received on vif: %pM\n",
2262 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
2263 ath_dbg(common, CHAN_CTX, "Starting HW scan\n");
2264 ath_offchannel_next(sc);
2268 mutex_unlock(&sc->mutex);
2273 static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw,
2274 struct ieee80211_vif *vif)
2276 struct ath_softc *sc = hw->priv;
2277 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2279 ath_dbg(common, CHAN_CTX, "Cancel HW scan on vif: %pM\n", vif->addr);
2281 mutex_lock(&sc->mutex);
2282 del_timer_sync(&sc->offchannel.timer);
2283 ath_scan_complete(sc, true);
2284 mutex_unlock(&sc->mutex);
2287 static int ath9k_remain_on_channel(struct ieee80211_hw *hw,
2288 struct ieee80211_vif *vif,
2289 struct ieee80211_channel *chan, int duration,
2290 enum ieee80211_roc_type type)
2292 struct ath_softc *sc = hw->priv;
2293 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2296 mutex_lock(&sc->mutex);
2298 if (WARN_ON(sc->offchannel.roc_vif)) {
2303 ath9k_ps_wakeup(sc);
2304 sc->offchannel.roc_vif = vif;
2305 sc->offchannel.roc_chan = chan;
2306 sc->offchannel.roc_duration = duration;
2308 ath_dbg(common, CHAN_CTX,
2309 "RoC request on vif: %pM, type: %d duration: %d\n",
2310 vif->addr, type, duration);
2312 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE) {
2313 ath_dbg(common, CHAN_CTX, "Starting RoC period\n");
2314 ath_offchannel_next(sc);
2318 mutex_unlock(&sc->mutex);
2323 static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2325 struct ath_softc *sc = hw->priv;
2326 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2328 mutex_lock(&sc->mutex);
2330 ath_dbg(common, CHAN_CTX, "Cancel RoC\n");
2331 del_timer_sync(&sc->offchannel.timer);
2333 if (sc->offchannel.roc_vif) {
2334 if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
2335 ath_roc_complete(sc, true);
2338 mutex_unlock(&sc->mutex);
2343 static int ath9k_add_chanctx(struct ieee80211_hw *hw,
2344 struct ieee80211_chanctx_conf *conf)
2346 struct ath_softc *sc = hw->priv;
2347 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2348 struct ath_chanctx *ctx, **ptr;
2351 mutex_lock(&sc->mutex);
2353 ath_for_each_chanctx(sc, ctx) {
2357 ptr = (void *) conf->drv_priv;
2359 ctx->assigned = true;
2360 pos = ctx - &sc->chanctx[0];
2361 ctx->hw_queue_base = pos * IEEE80211_NUM_ACS;
2363 ath_dbg(common, CHAN_CTX,
2364 "Add channel context: %d MHz\n",
2365 conf->def.chan->center_freq);
2367 ath_chanctx_set_channel(sc, ctx, &conf->def);
2368 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_ASSIGN);
2370 mutex_unlock(&sc->mutex);
2374 mutex_unlock(&sc->mutex);
2379 static void ath9k_remove_chanctx(struct ieee80211_hw *hw,
2380 struct ieee80211_chanctx_conf *conf)
2382 struct ath_softc *sc = hw->priv;
2383 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2384 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2386 mutex_lock(&sc->mutex);
2388 ath_dbg(common, CHAN_CTX,
2389 "Remove channel context: %d MHz\n",
2390 conf->def.chan->center_freq);
2392 ctx->assigned = false;
2393 ctx->hw_queue_base = 0;
2394 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_UNASSIGN);
2396 mutex_unlock(&sc->mutex);
2399 static void ath9k_change_chanctx(struct ieee80211_hw *hw,
2400 struct ieee80211_chanctx_conf *conf,
2403 struct ath_softc *sc = hw->priv;
2404 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2405 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2407 mutex_lock(&sc->mutex);
2408 ath_dbg(common, CHAN_CTX,
2409 "Change channel context: %d MHz\n",
2410 conf->def.chan->center_freq);
2411 ath_chanctx_set_channel(sc, ctx, &conf->def);
2412 mutex_unlock(&sc->mutex);
2415 static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
2416 struct ieee80211_vif *vif,
2417 struct ieee80211_chanctx_conf *conf)
2419 struct ath_softc *sc = hw->priv;
2420 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2421 struct ath_vif *avp = (void *)vif->drv_priv;
2422 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2425 mutex_lock(&sc->mutex);
2427 ath_dbg(common, CHAN_CTX,
2428 "Assign VIF (addr: %pM, type: %d, p2p: %d) to channel context: %d MHz\n",
2429 vif->addr, vif->type, vif->p2p,
2430 conf->def.chan->center_freq);
2433 ctx->nvifs_assigned++;
2434 list_add_tail(&avp->list, &ctx->vifs);
2435 ath9k_calculate_summary_state(sc, ctx);
2436 for (i = 0; i < IEEE80211_NUM_ACS; i++)
2437 vif->hw_queue[i] = ctx->hw_queue_base + i;
2439 mutex_unlock(&sc->mutex);
2444 static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
2445 struct ieee80211_vif *vif,
2446 struct ieee80211_chanctx_conf *conf)
2448 struct ath_softc *sc = hw->priv;
2449 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2450 struct ath_vif *avp = (void *)vif->drv_priv;
2451 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2454 mutex_lock(&sc->mutex);
2456 ath_dbg(common, CHAN_CTX,
2457 "Remove VIF (addr: %pM, type: %d, p2p: %d) from channel context: %d MHz\n",
2458 vif->addr, vif->type, vif->p2p,
2459 conf->def.chan->center_freq);
2461 avp->chanctx = NULL;
2462 ctx->nvifs_assigned--;
2463 list_del(&avp->list);
2464 ath9k_calculate_summary_state(sc, ctx);
2465 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2466 vif->hw_queue[ac] = IEEE80211_INVAL_HW_QUEUE;
2468 mutex_unlock(&sc->mutex);
2471 static void ath9k_mgd_prepare_tx(struct ieee80211_hw *hw,
2472 struct ieee80211_vif *vif)
2474 struct ath_softc *sc = hw->priv;
2475 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2476 struct ath_vif *avp = (struct ath_vif *) vif->drv_priv;
2477 struct ath_beacon_config *cur_conf;
2478 struct ath_chanctx *go_ctx;
2479 unsigned long timeout;
2480 bool changed = false;
2483 if (!test_bit(ATH_OP_MULTI_CHANNEL, &common->op_flags))
2489 mutex_lock(&sc->mutex);
2491 spin_lock_bh(&sc->chan_lock);
2492 if (sc->next_chan || (sc->cur_chan != avp->chanctx))
2494 spin_unlock_bh(&sc->chan_lock);
2499 go_ctx = ath_is_go_chanctx_present(sc);
2503 * Wait till the GO interface gets a chance
2504 * to send out an NoA.
2506 spin_lock_bh(&sc->chan_lock);
2507 sc->sched.mgd_prepare_tx = true;
2508 cur_conf = &go_ctx->beacon;
2509 beacon_int = TU_TO_USEC(cur_conf->beacon_interval);
2510 spin_unlock_bh(&sc->chan_lock);
2512 timeout = usecs_to_jiffies(beacon_int);
2513 init_completion(&sc->go_beacon);
2515 if (wait_for_completion_timeout(&sc->go_beacon,
2517 ath_dbg(common, CHAN_CTX,
2518 "Failed to send new NoA\n");
2521 ath_dbg(common, CHAN_CTX,
2522 "%s: Set chanctx state to FORCE_ACTIVE for vif: %pM\n",
2523 __func__, vif->addr);
2525 spin_lock_bh(&sc->chan_lock);
2526 sc->next_chan = avp->chanctx;
2527 sc->sched.state = ATH_CHANCTX_STATE_FORCE_ACTIVE;
2528 spin_unlock_bh(&sc->chan_lock);
2530 ath_chanctx_set_next(sc, true);
2532 mutex_unlock(&sc->mutex);
2535 void ath9k_fill_chanctx_ops(void)
2537 if (!ath9k_is_chanctx_enabled())
2540 ath9k_ops.hw_scan = ath9k_hw_scan;
2541 ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
2542 ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
2543 ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
2544 ath9k_ops.add_chanctx = ath9k_add_chanctx;
2545 ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
2546 ath9k_ops.change_chanctx = ath9k_change_chanctx;
2547 ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
2548 ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
2549 ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
2554 struct ieee80211_ops ath9k_ops = {
2556 .start = ath9k_start,
2558 .add_interface = ath9k_add_interface,
2559 .change_interface = ath9k_change_interface,
2560 .remove_interface = ath9k_remove_interface,
2561 .config = ath9k_config,
2562 .configure_filter = ath9k_configure_filter,
2563 .sta_state = ath9k_sta_state,
2564 .sta_notify = ath9k_sta_notify,
2565 .conf_tx = ath9k_conf_tx,
2566 .bss_info_changed = ath9k_bss_info_changed,
2567 .set_key = ath9k_set_key,
2568 .get_tsf = ath9k_get_tsf,
2569 .set_tsf = ath9k_set_tsf,
2570 .reset_tsf = ath9k_reset_tsf,
2571 .ampdu_action = ath9k_ampdu_action,
2572 .get_survey = ath9k_get_survey,
2573 .rfkill_poll = ath9k_rfkill_poll_state,
2574 .set_coverage_class = ath9k_set_coverage_class,
2575 .flush = ath9k_flush,
2576 .tx_frames_pending = ath9k_tx_frames_pending,
2577 .tx_last_beacon = ath9k_tx_last_beacon,
2578 .release_buffered_frames = ath9k_release_buffered_frames,
2579 .get_stats = ath9k_get_stats,
2580 .set_antenna = ath9k_set_antenna,
2581 .get_antenna = ath9k_get_antenna,
2583 #ifdef CONFIG_ATH9K_WOW
2584 .suspend = ath9k_suspend,
2585 .resume = ath9k_resume,
2586 .set_wakeup = ath9k_set_wakeup,
2589 #ifdef CONFIG_ATH9K_DEBUGFS
2590 .get_et_sset_count = ath9k_get_et_sset_count,
2591 .get_et_stats = ath9k_get_et_stats,
2592 .get_et_strings = ath9k_get_et_strings,
2595 #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
2596 .sta_add_debugfs = ath9k_sta_add_debugfs,
2598 .sw_scan_start = ath9k_sw_scan_start,
2599 .sw_scan_complete = ath9k_sw_scan_complete,