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)
61 spin_lock_bh(&txq->axq_lock);
66 if (txq->mac80211_qnum >= 0) {
67 struct list_head *list;
69 list = &sc->cur_chan->acq[txq->mac80211_qnum];
70 if (!list_empty(list))
73 spin_unlock_bh(&txq->axq_lock);
77 static bool ath9k_setpower(struct ath_softc *sc, enum ath9k_power_mode mode)
82 spin_lock_irqsave(&sc->sc_pm_lock, flags);
83 ret = ath9k_hw_setpower(sc->sc_ah, mode);
84 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
89 void ath_ps_full_sleep(unsigned long data)
91 struct ath_softc *sc = (struct ath_softc *) data;
92 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
95 spin_lock(&common->cc_lock);
96 ath_hw_cycle_counters_update(common);
97 spin_unlock(&common->cc_lock);
99 ath9k_hw_setrxabort(sc->sc_ah, 1);
100 ath9k_hw_stopdmarecv(sc->sc_ah, &reset);
102 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
105 void ath9k_ps_wakeup(struct ath_softc *sc)
107 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
109 enum ath9k_power_mode power_mode;
111 spin_lock_irqsave(&sc->sc_pm_lock, flags);
112 if (++sc->ps_usecount != 1)
115 del_timer_sync(&sc->sleep_timer);
116 power_mode = sc->sc_ah->power_mode;
117 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
120 * While the hardware is asleep, the cycle counters contain no
121 * useful data. Better clear them now so that they don't mess up
122 * survey data results.
124 if (power_mode != ATH9K_PM_AWAKE) {
125 spin_lock(&common->cc_lock);
126 ath_hw_cycle_counters_update(common);
127 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
128 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
129 spin_unlock(&common->cc_lock);
133 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
136 void ath9k_ps_restore(struct ath_softc *sc)
138 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
139 enum ath9k_power_mode mode;
142 spin_lock_irqsave(&sc->sc_pm_lock, flags);
143 if (--sc->ps_usecount != 0)
147 mod_timer(&sc->sleep_timer, jiffies + HZ / 10);
151 if (sc->ps_enabled &&
152 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
154 PS_WAIT_FOR_PSPOLL_DATA |
157 mode = ATH9K_PM_NETWORK_SLEEP;
158 if (ath9k_hw_btcoex_is_enabled(sc->sc_ah))
159 ath9k_btcoex_stop_gen_timer(sc);
164 spin_lock(&common->cc_lock);
165 ath_hw_cycle_counters_update(common);
166 spin_unlock(&common->cc_lock);
168 ath9k_hw_setpower(sc->sc_ah, mode);
171 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
174 static void __ath_cancel_work(struct ath_softc *sc)
176 cancel_work_sync(&sc->paprd_work);
177 cancel_delayed_work_sync(&sc->tx_complete_work);
178 cancel_delayed_work_sync(&sc->hw_pll_work);
180 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
181 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
182 cancel_work_sync(&sc->mci_work);
186 void ath_cancel_work(struct ath_softc *sc)
188 __ath_cancel_work(sc);
189 cancel_work_sync(&sc->hw_reset_work);
192 void ath_restart_work(struct ath_softc *sc)
194 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
196 if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
197 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
198 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
203 static bool ath_prepare_reset(struct ath_softc *sc)
205 struct ath_hw *ah = sc->sc_ah;
208 ieee80211_stop_queues(sc->hw);
210 ath9k_hw_disable_interrupts(ah);
212 if (!ath_drain_all_txq(sc))
215 if (!ath_stoprecv(sc))
221 static bool ath_complete_reset(struct ath_softc *sc, bool start)
223 struct ath_hw *ah = sc->sc_ah;
224 struct ath_common *common = ath9k_hw_common(ah);
227 if (ath_startrecv(sc) != 0) {
228 ath_err(common, "Unable to restart recv logic\n");
232 ath9k_cmn_update_txpow(ah, sc->curtxpow,
233 sc->cur_chan->txpower, &sc->curtxpow);
235 clear_bit(ATH_OP_HW_RESET, &common->op_flags);
236 ath9k_calculate_summary_state(sc, sc->cur_chan);
238 if (!sc->cur_chan->offchannel && start) {
239 /* restore per chanctx TSF timer */
240 if (sc->cur_chan->tsf_val) {
243 offset = ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts,
245 ath9k_hw_settsf64(ah, sc->cur_chan->tsf_val + offset);
249 if (!test_bit(ATH_OP_BEACONS, &common->op_flags))
252 if (ah->opmode == NL80211_IFTYPE_STATION &&
253 test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
254 spin_lock_irqsave(&sc->sc_pm_lock, flags);
255 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
256 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
258 ath9k_set_beacon(sc);
261 ath_restart_work(sc);
262 ath_txq_schedule_all(sc);
267 ath9k_hw_set_interrupts(ah);
268 ath9k_hw_enable_interrupts(ah);
270 ieee80211_wake_queues(sc->hw);
272 ath9k_p2p_ps_timer(sc);
277 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 spin_lock_bh(&sc->sc_pcu_lock);
290 if (!sc->cur_chan->offchannel) {
292 caldata = &sc->cur_chan->caldata;
300 if (!ath_prepare_reset(sc))
304 spin_lock_bh(&sc->chan_lock);
305 sc->cur_chandef = sc->cur_chan->chandef;
306 spin_unlock_bh(&sc->chan_lock);
309 ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
310 hchan->channel, IS_CHAN_HT40(hchan), fastcc);
312 r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
315 "Unable to reset channel, reset status %d\n", r);
317 ath9k_hw_enable_interrupts(ah);
318 ath9k_queue_reset(sc, RESET_TYPE_BB_HANG);
323 if (ath9k_hw_mci_is_enabled(sc->sc_ah) &&
324 sc->cur_chan->offchannel)
325 ath9k_mci_set_txpower(sc, true, false);
327 if (!ath_complete_reset(sc, true))
331 spin_unlock_bh(&sc->sc_pcu_lock);
332 tasklet_enable(&sc->intr_tq);
337 static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
338 struct ieee80211_vif *vif)
341 an = (struct ath_node *)sta->drv_priv;
346 memset(&an->key_idx, 0, sizeof(an->key_idx));
348 ath_tx_node_init(sc, an);
351 static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
353 struct ath_node *an = (struct ath_node *)sta->drv_priv;
354 ath_tx_node_cleanup(sc, an);
357 void ath9k_tasklet(unsigned long data)
359 struct ath_softc *sc = (struct ath_softc *)data;
360 struct ath_hw *ah = sc->sc_ah;
361 struct ath_common *common = ath9k_hw_common(ah);
362 enum ath_reset_type type;
364 u32 status = sc->intrstatus;
368 spin_lock(&sc->sc_pcu_lock);
370 if (status & ATH9K_INT_FATAL) {
371 type = RESET_TYPE_FATAL_INT;
372 ath9k_queue_reset(sc, type);
375 * Increment the ref. counter here so that
376 * interrupts are enabled in the reset routine.
378 atomic_inc(&ah->intr_ref_cnt);
379 ath_dbg(common, RESET, "FATAL: Skipping interrupts\n");
383 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
384 (status & ATH9K_INT_BB_WATCHDOG)) {
385 spin_lock(&common->cc_lock);
386 ath_hw_cycle_counters_update(common);
387 ar9003_hw_bb_watchdog_dbg_info(ah);
388 spin_unlock(&common->cc_lock);
390 if (ar9003_hw_bb_watchdog_check(ah)) {
391 type = RESET_TYPE_BB_WATCHDOG;
392 ath9k_queue_reset(sc, type);
395 * Increment the ref. counter here so that
396 * interrupts are enabled in the reset routine.
398 atomic_inc(&ah->intr_ref_cnt);
399 ath_dbg(common, RESET,
400 "BB_WATCHDOG: Skipping interrupts\n");
405 if (status & ATH9K_INT_GTT) {
408 if ((sc->gtt_cnt >= MAX_GTT_CNT) && !ath9k_hw_check_alive(ah)) {
409 type = RESET_TYPE_TX_GTT;
410 ath9k_queue_reset(sc, type);
411 atomic_inc(&ah->intr_ref_cnt);
412 ath_dbg(common, RESET,
413 "GTT: Skipping interrupts\n");
418 spin_lock_irqsave(&sc->sc_pm_lock, flags);
419 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
421 * TSF sync does not look correct; remain awake to sync with
424 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
425 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
427 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
429 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
430 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
433 rxmask = (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
435 if (status & rxmask) {
436 /* Check for high priority Rx first */
437 if ((ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) &&
438 (status & ATH9K_INT_RXHP))
439 ath_rx_tasklet(sc, 0, true);
441 ath_rx_tasklet(sc, 0, false);
444 if (status & ATH9K_INT_TX) {
445 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
447 * For EDMA chips, TX completion is enabled for the
448 * beacon queue, so if a beacon has been transmitted
449 * successfully after a GTT interrupt, the GTT counter
450 * gets reset to zero here.
454 ath_tx_edma_tasklet(sc);
459 wake_up(&sc->tx_wait);
462 if (status & ATH9K_INT_GENTIMER)
463 ath_gen_timer_isr(sc->sc_ah);
465 ath9k_btcoex_handle_interrupt(sc, status);
467 /* re-enable hardware interrupt */
468 ath9k_hw_enable_interrupts(ah);
470 spin_unlock(&sc->sc_pcu_lock);
471 ath9k_ps_restore(sc);
474 irqreturn_t ath_isr(int irq, void *dev)
476 #define SCHED_INTR ( \
478 ATH9K_INT_BB_WATCHDOG | \
489 ATH9K_INT_GENTIMER | \
492 struct ath_softc *sc = dev;
493 struct ath_hw *ah = sc->sc_ah;
494 struct ath_common *common = ath9k_hw_common(ah);
495 enum ath9k_int status;
500 * The hardware is not ready/present, don't
501 * touch anything. Note this can happen early
502 * on if the IRQ is shared.
504 if (test_bit(ATH_OP_INVALID, &common->op_flags))
507 /* shared irq, not for us */
509 if (!ath9k_hw_intrpend(ah))
512 if (test_bit(ATH_OP_HW_RESET, &common->op_flags)) {
513 ath9k_hw_kill_interrupts(ah);
518 * Figure out the reason(s) for the interrupt. Note
519 * that the hal returns a pseudo-ISR that may include
520 * bits we haven't explicitly enabled so we mask the
521 * value to insure we only process bits we requested.
523 ath9k_hw_getisr(ah, &status, &sync_cause); /* NB: clears ISR too */
524 ath9k_debug_sync_cause(sc, sync_cause);
525 status &= ah->imask; /* discard unasked-for bits */
528 * If there are no status bits set, then this interrupt was not
529 * for me (should have been caught above).
534 /* Cache the status */
535 sc->intrstatus = status;
537 if (status & SCHED_INTR)
541 * If a FATAL or RXORN interrupt is received, we have to reset the
544 if ((status & ATH9K_INT_FATAL) || ((status & ATH9K_INT_RXORN) &&
545 !(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)))
548 if ((ah->config.hw_hang_checks & HW_BB_WATCHDOG) &&
549 (status & ATH9K_INT_BB_WATCHDOG))
552 #ifdef CONFIG_ATH9K_WOW
553 if (status & ATH9K_INT_BMISS) {
554 if (atomic_read(&sc->wow_sleep_proc_intr) == 0) {
555 atomic_inc(&sc->wow_got_bmiss_intr);
556 atomic_dec(&sc->wow_sleep_proc_intr);
561 if (status & ATH9K_INT_SWBA)
562 tasklet_schedule(&sc->bcon_tasklet);
564 if (status & ATH9K_INT_TXURN)
565 ath9k_hw_updatetxtriglevel(ah, true);
567 if (status & ATH9K_INT_RXEOL) {
568 ah->imask &= ~(ATH9K_INT_RXEOL | ATH9K_INT_RXORN);
569 ath9k_hw_set_interrupts(ah);
572 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
573 if (status & ATH9K_INT_TIM_TIMER) {
574 if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
576 /* Clear RxAbort bit so that we can
578 ath9k_setpower(sc, ATH9K_PM_AWAKE);
579 spin_lock(&sc->sc_pm_lock);
580 ath9k_hw_setrxabort(sc->sc_ah, 0);
581 sc->ps_flags |= PS_WAIT_FOR_BEACON;
582 spin_unlock(&sc->sc_pm_lock);
587 ath_debug_stat_interrupt(sc, status);
590 /* turn off every interrupt */
591 ath9k_hw_disable_interrupts(ah);
592 tasklet_schedule(&sc->intr_tq);
600 int ath_reset(struct ath_softc *sc)
605 r = ath_reset_internal(sc, NULL);
606 ath9k_ps_restore(sc);
611 void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type)
613 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
614 #ifdef CONFIG_ATH9K_DEBUGFS
615 RESET_STAT_INC(sc, type);
617 set_bit(ATH_OP_HW_RESET, &common->op_flags);
618 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
621 void ath_reset_work(struct work_struct *work)
623 struct ath_softc *sc = container_of(work, struct ath_softc, hw_reset_work);
628 /**********************/
629 /* mac80211 callbacks */
630 /**********************/
632 static int ath9k_start(struct ieee80211_hw *hw)
634 struct ath_softc *sc = hw->priv;
635 struct ath_hw *ah = sc->sc_ah;
636 struct ath_common *common = ath9k_hw_common(ah);
637 struct ieee80211_channel *curchan = sc->cur_chan->chandef.chan;
638 struct ath_chanctx *ctx = sc->cur_chan;
639 struct ath9k_channel *init_channel;
642 ath_dbg(common, CONFIG,
643 "Starting driver with initial channel: %d MHz\n",
644 curchan->center_freq);
647 mutex_lock(&sc->mutex);
649 init_channel = ath9k_cmn_get_channel(hw, ah, &ctx->chandef);
650 sc->cur_chandef = hw->conf.chandef;
652 /* Reset SERDES registers */
653 ath9k_hw_configpcipowersave(ah, false);
656 * The basic interface to setting the hardware in a good
657 * state is ``reset''. On return the hardware is known to
658 * be powered up and with interrupts disabled. This must
659 * be followed by initialization of the appropriate bits
660 * and then setup of the interrupt mask.
662 spin_lock_bh(&sc->sc_pcu_lock);
664 atomic_set(&ah->intr_ref_cnt, -1);
666 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
669 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
670 r, curchan->center_freq);
671 ah->reset_power_on = false;
674 /* Setup our intr mask. */
675 ah->imask = ATH9K_INT_TX | ATH9K_INT_RXEOL |
676 ATH9K_INT_RXORN | ATH9K_INT_FATAL |
679 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
680 ah->imask |= ATH9K_INT_RXHP |
683 ah->imask |= ATH9K_INT_RX;
685 if (ah->config.hw_hang_checks & HW_BB_WATCHDOG)
686 ah->imask |= ATH9K_INT_BB_WATCHDOG;
689 * Enable GTT interrupts only for AR9003/AR9004 chips
692 if (AR_SREV_9300_20_OR_LATER(ah))
693 ah->imask |= ATH9K_INT_GTT;
695 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
696 ah->imask |= ATH9K_INT_CST;
700 clear_bit(ATH_OP_INVALID, &common->op_flags);
701 sc->sc_ah->is_monitoring = false;
703 if (!ath_complete_reset(sc, false))
704 ah->reset_power_on = false;
706 if (ah->led_pin >= 0) {
707 ath9k_hw_cfg_output(ah, ah->led_pin,
708 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
709 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
713 * Reset key cache to sane defaults (all entries cleared) instead of
714 * semi-random values after suspend/resume.
716 ath9k_cmn_init_crypto(sc->sc_ah);
718 ath9k_hw_reset_tsf(ah);
720 spin_unlock_bh(&sc->sc_pcu_lock);
722 mutex_unlock(&sc->mutex);
724 ath9k_ps_restore(sc);
729 static void ath9k_tx(struct ieee80211_hw *hw,
730 struct ieee80211_tx_control *control,
733 struct ath_softc *sc = hw->priv;
734 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
735 struct ath_tx_control txctl;
736 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
739 if (sc->ps_enabled) {
741 * mac80211 does not set PM field for normal data frames, so we
742 * need to update that based on the current PS mode.
744 if (ieee80211_is_data(hdr->frame_control) &&
745 !ieee80211_is_nullfunc(hdr->frame_control) &&
746 !ieee80211_has_pm(hdr->frame_control)) {
748 "Add PM=1 for a TX frame while in PS mode\n");
749 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
753 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_NETWORK_SLEEP)) {
755 * We are using PS-Poll and mac80211 can request TX while in
756 * power save mode. Need to wake up hardware for the TX to be
757 * completed and if needed, also for RX of buffered frames.
760 spin_lock_irqsave(&sc->sc_pm_lock, flags);
761 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
762 ath9k_hw_setrxabort(sc->sc_ah, 0);
763 if (ieee80211_is_pspoll(hdr->frame_control)) {
765 "Sending PS-Poll to pick a buffered frame\n");
766 sc->ps_flags |= PS_WAIT_FOR_PSPOLL_DATA;
768 ath_dbg(common, PS, "Wake up to complete TX\n");
769 sc->ps_flags |= PS_WAIT_FOR_TX_ACK;
772 * The actual restore operation will happen only after
773 * the ps_flags bit is cleared. We are just dropping
774 * the ps_usecount here.
776 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
777 ath9k_ps_restore(sc);
781 * Cannot tx while the hardware is in full sleep, it first needs a full
782 * chip reset to recover from that
784 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP)) {
785 ath_err(common, "TX while HW is in FULL_SLEEP mode\n");
789 memset(&txctl, 0, sizeof(struct ath_tx_control));
790 txctl.txq = sc->tx.txq_map[skb_get_queue_mapping(skb)];
791 txctl.sta = control->sta;
793 ath_dbg(common, XMIT, "transmitting packet, skb: %p\n", skb);
795 if (ath_tx_start(hw, skb, &txctl) != 0) {
796 ath_dbg(common, XMIT, "TX failed\n");
797 TX_STAT_INC(txctl.txq->axq_qnum, txfailed);
803 ieee80211_free_txskb(hw, skb);
806 static void ath9k_stop(struct ieee80211_hw *hw)
808 struct ath_softc *sc = hw->priv;
809 struct ath_hw *ah = sc->sc_ah;
810 struct ath_common *common = ath9k_hw_common(ah);
813 cancel_work_sync(&sc->chanctx_work);
814 mutex_lock(&sc->mutex);
818 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
819 ath_dbg(common, ANY, "Device not present\n");
820 mutex_unlock(&sc->mutex);
824 /* Ensure HW is awake when we try to shut it down. */
827 spin_lock_bh(&sc->sc_pcu_lock);
829 /* prevent tasklets to enable interrupts once we disable them */
830 ah->imask &= ~ATH9K_INT_GLOBAL;
832 /* make sure h/w will not generate any interrupt
833 * before setting the invalid flag. */
834 ath9k_hw_disable_interrupts(ah);
836 spin_unlock_bh(&sc->sc_pcu_lock);
838 /* we can now sync irq and kill any running tasklets, since we already
839 * disabled interrupts and not holding a spin lock */
840 synchronize_irq(sc->irq);
841 tasklet_kill(&sc->intr_tq);
842 tasklet_kill(&sc->bcon_tasklet);
844 prev_idle = sc->ps_idle;
847 spin_lock_bh(&sc->sc_pcu_lock);
849 if (ah->led_pin >= 0) {
850 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
851 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
854 ath_prepare_reset(sc);
857 dev_kfree_skb_any(sc->rx.frag);
862 ah->curchan = ath9k_cmn_get_channel(hw, ah,
863 &sc->cur_chan->chandef);
865 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
866 ath9k_hw_phy_disable(ah);
868 ath9k_hw_configpcipowersave(ah, true);
870 spin_unlock_bh(&sc->sc_pcu_lock);
872 ath9k_ps_restore(sc);
874 set_bit(ATH_OP_INVALID, &common->op_flags);
875 sc->ps_idle = prev_idle;
877 mutex_unlock(&sc->mutex);
879 ath_dbg(common, CONFIG, "Driver halt\n");
882 static bool ath9k_uses_beacons(int type)
885 case NL80211_IFTYPE_AP:
886 case NL80211_IFTYPE_ADHOC:
887 case NL80211_IFTYPE_MESH_POINT:
894 static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
896 struct ath9k_vif_iter_data *iter_data = data;
899 if (iter_data->has_hw_macaddr) {
900 for (i = 0; i < ETH_ALEN; i++)
901 iter_data->mask[i] &=
902 ~(iter_data->hw_macaddr[i] ^ mac[i]);
904 memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
905 iter_data->has_hw_macaddr = true;
908 if (!vif->bss_conf.use_short_slot)
909 iter_data->slottime = ATH9K_SLOT_TIME_20;
912 case NL80211_IFTYPE_AP:
914 if (vif->bss_conf.enable_beacon)
915 iter_data->beacons = true;
917 case NL80211_IFTYPE_STATION:
918 iter_data->nstations++;
919 if (vif->bss_conf.assoc && !iter_data->primary_sta)
920 iter_data->primary_sta = vif;
922 case NL80211_IFTYPE_ADHOC:
923 iter_data->nadhocs++;
924 if (vif->bss_conf.enable_beacon)
925 iter_data->beacons = true;
927 case NL80211_IFTYPE_MESH_POINT:
928 iter_data->nmeshes++;
929 if (vif->bss_conf.enable_beacon)
930 iter_data->beacons = true;
932 case NL80211_IFTYPE_WDS:
940 /* Called with sc->mutex held. */
941 void ath9k_calculate_iter_data(struct ath_softc *sc,
942 struct ath_chanctx *ctx,
943 struct ath9k_vif_iter_data *iter_data)
948 * Pick the MAC address of the first interface as the new hardware
949 * MAC address. The hardware will use it together with the BSSID mask
950 * when matching addresses.
952 memset(iter_data, 0, sizeof(*iter_data));
953 memset(&iter_data->mask, 0xff, ETH_ALEN);
954 iter_data->slottime = ATH9K_SLOT_TIME_9;
956 list_for_each_entry(avp, &ctx->vifs, list)
957 ath9k_vif_iter(iter_data, avp->vif->addr, avp->vif);
959 if (ctx == &sc->offchannel.chan) {
960 struct ieee80211_vif *vif;
962 if (sc->offchannel.state < ATH_OFFCHANNEL_ROC_START)
963 vif = sc->offchannel.scan_vif;
965 vif = sc->offchannel.roc_vif;
968 ath9k_vif_iter(iter_data, vif->addr, vif);
969 iter_data->beacons = false;
973 static void ath9k_set_assoc_state(struct ath_softc *sc,
974 struct ieee80211_vif *vif, bool changed)
976 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
977 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
980 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
981 /* Set the AID, BSSID and do beacon-sync only when
982 * the HW opmode is STATION.
984 * But the primary bit is set above in any case.
986 if (sc->sc_ah->opmode != NL80211_IFTYPE_STATION)
989 ether_addr_copy(common->curbssid, bss_conf->bssid);
990 common->curaid = bss_conf->aid;
991 ath9k_hw_write_associd(sc->sc_ah);
994 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
995 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
997 spin_lock_irqsave(&sc->sc_pm_lock, flags);
998 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
999 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1002 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1003 ath9k_mci_update_wlan_channels(sc, false);
1005 ath_dbg(common, CONFIG,
1006 "Primary Station interface: %pM, BSSID: %pM\n",
1007 vif->addr, common->curbssid);
1010 /* Called with sc->mutex held. */
1011 void ath9k_calculate_summary_state(struct ath_softc *sc,
1012 struct ath_chanctx *ctx)
1014 struct ath_hw *ah = sc->sc_ah;
1015 struct ath_common *common = ath9k_hw_common(ah);
1016 struct ath9k_vif_iter_data iter_data;
1018 ath_chanctx_check_active(sc, ctx);
1020 if (ctx != sc->cur_chan)
1023 ath9k_ps_wakeup(sc);
1024 ath9k_calculate_iter_data(sc, ctx, &iter_data);
1026 if (iter_data.has_hw_macaddr)
1027 ether_addr_copy(common->macaddr, iter_data.hw_macaddr);
1029 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
1030 ath_hw_setbssidmask(common);
1032 if (iter_data.naps > 0) {
1033 ath9k_hw_set_tsfadjust(ah, true);
1034 ah->opmode = NL80211_IFTYPE_AP;
1036 ath9k_hw_set_tsfadjust(ah, false);
1038 if (iter_data.nmeshes)
1039 ah->opmode = NL80211_IFTYPE_MESH_POINT;
1040 else if (iter_data.nwds)
1041 ah->opmode = NL80211_IFTYPE_AP;
1042 else if (iter_data.nadhocs)
1043 ah->opmode = NL80211_IFTYPE_ADHOC;
1045 ah->opmode = NL80211_IFTYPE_STATION;
1048 ath9k_hw_setopmode(ah);
1050 if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
1051 ah->imask |= ATH9K_INT_TSFOOR;
1053 ah->imask &= ~ATH9K_INT_TSFOOR;
1055 ah->imask &= ~ATH9K_INT_SWBA;
1056 if (ah->opmode == NL80211_IFTYPE_STATION) {
1057 bool changed = (iter_data.primary_sta != ctx->primary_sta);
1059 iter_data.beacons = true;
1060 if (iter_data.primary_sta) {
1061 ath9k_set_assoc_state(sc, iter_data.primary_sta,
1063 if (!ctx->primary_sta ||
1064 !ctx->primary_sta->bss_conf.assoc)
1065 ctx->primary_sta = iter_data.primary_sta;
1067 ctx->primary_sta = NULL;
1068 memset(common->curbssid, 0, ETH_ALEN);
1070 ath9k_hw_write_associd(sc->sc_ah);
1071 if (ath9k_hw_mci_is_enabled(sc->sc_ah))
1072 ath9k_mci_update_wlan_channels(sc, true);
1074 } else if (iter_data.beacons) {
1075 ah->imask |= ATH9K_INT_SWBA;
1077 ath9k_hw_set_interrupts(ah);
1079 if (iter_data.beacons)
1080 set_bit(ATH_OP_BEACONS, &common->op_flags);
1082 clear_bit(ATH_OP_BEACONS, &common->op_flags);
1084 if (ah->slottime != iter_data.slottime) {
1085 ah->slottime = iter_data.slottime;
1086 ath9k_hw_init_global_settings(ah);
1089 if (iter_data.primary_sta)
1090 set_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1092 clear_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags);
1094 ctx->primary_sta = iter_data.primary_sta;
1096 ath9k_ps_restore(sc);
1099 static int ath9k_add_interface(struct ieee80211_hw *hw,
1100 struct ieee80211_vif *vif)
1102 struct ath_softc *sc = hw->priv;
1103 struct ath_hw *ah = sc->sc_ah;
1104 struct ath_common *common = ath9k_hw_common(ah);
1105 struct ath_vif *avp = (void *)vif->drv_priv;
1106 struct ath_node *an = &avp->mcast_node;
1108 mutex_lock(&sc->mutex);
1110 if (config_enabled(CONFIG_ATH9K_TX99)) {
1111 if (sc->nvifs >= 1) {
1112 mutex_unlock(&sc->mutex);
1118 ath_dbg(common, CONFIG, "Attach a VIF of type: %d\n", vif->type);
1121 if (ath9k_uses_beacons(vif->type))
1122 ath9k_beacon_assign_slot(sc, vif);
1125 if (!ath9k_use_chanctx) {
1126 avp->chanctx = sc->cur_chan;
1127 list_add_tail(&avp->list, &avp->chanctx->vifs);
1133 an->no_ps_filter = true;
1134 ath_tx_node_init(sc, an);
1136 mutex_unlock(&sc->mutex);
1140 static int ath9k_change_interface(struct ieee80211_hw *hw,
1141 struct ieee80211_vif *vif,
1142 enum nl80211_iftype new_type,
1145 struct ath_softc *sc = hw->priv;
1146 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1147 struct ath_vif *avp = (void *)vif->drv_priv;
1149 mutex_lock(&sc->mutex);
1151 if (config_enabled(CONFIG_ATH9K_TX99)) {
1152 mutex_unlock(&sc->mutex);
1156 ath_dbg(common, CONFIG, "Change Interface\n");
1158 if (ath9k_uses_beacons(vif->type))
1159 ath9k_beacon_remove_slot(sc, vif);
1161 vif->type = new_type;
1164 if (ath9k_uses_beacons(vif->type))
1165 ath9k_beacon_assign_slot(sc, vif);
1167 ath9k_calculate_summary_state(sc, avp->chanctx);
1169 mutex_unlock(&sc->mutex);
1174 ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
1176 struct ath_hw *ah = sc->sc_ah;
1177 s32 tsf, target_tsf;
1179 if (!avp || !avp->noa.has_next_tsf)
1182 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
1184 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1186 target_tsf = avp->noa.next_tsf;
1187 if (!avp->noa.absent)
1188 target_tsf -= ATH_P2P_PS_STOP_TIME;
1190 if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
1191 target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
1193 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
1196 static void ath9k_remove_interface(struct ieee80211_hw *hw,
1197 struct ieee80211_vif *vif)
1199 struct ath_softc *sc = hw->priv;
1200 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1201 struct ath_vif *avp = (void *)vif->drv_priv;
1203 ath_dbg(common, CONFIG, "Detach Interface\n");
1205 mutex_lock(&sc->mutex);
1207 spin_lock_bh(&sc->sc_pcu_lock);
1208 if (avp == sc->p2p_ps_vif) {
1209 sc->p2p_ps_vif = NULL;
1210 ath9k_update_p2p_ps_timer(sc, NULL);
1212 spin_unlock_bh(&sc->sc_pcu_lock);
1215 sc->tx99_vif = NULL;
1216 if (!ath9k_use_chanctx)
1217 list_del(&avp->list);
1219 if (ath9k_uses_beacons(vif->type))
1220 ath9k_beacon_remove_slot(sc, vif);
1222 ath_tx_node_cleanup(sc, &avp->mcast_node);
1224 mutex_unlock(&sc->mutex);
1227 static void ath9k_enable_ps(struct ath_softc *sc)
1229 struct ath_hw *ah = sc->sc_ah;
1230 struct ath_common *common = ath9k_hw_common(ah);
1232 if (config_enabled(CONFIG_ATH9K_TX99))
1235 sc->ps_enabled = true;
1236 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1237 if ((ah->imask & ATH9K_INT_TIM_TIMER) == 0) {
1238 ah->imask |= ATH9K_INT_TIM_TIMER;
1239 ath9k_hw_set_interrupts(ah);
1241 ath9k_hw_setrxabort(ah, 1);
1243 ath_dbg(common, PS, "PowerSave enabled\n");
1246 static void ath9k_disable_ps(struct ath_softc *sc)
1248 struct ath_hw *ah = sc->sc_ah;
1249 struct ath_common *common = ath9k_hw_common(ah);
1251 if (config_enabled(CONFIG_ATH9K_TX99))
1254 sc->ps_enabled = false;
1255 ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
1256 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1257 ath9k_hw_setrxabort(ah, 0);
1258 sc->ps_flags &= ~(PS_WAIT_FOR_BEACON |
1260 PS_WAIT_FOR_PSPOLL_DATA |
1261 PS_WAIT_FOR_TX_ACK);
1262 if (ah->imask & ATH9K_INT_TIM_TIMER) {
1263 ah->imask &= ~ATH9K_INT_TIM_TIMER;
1264 ath9k_hw_set_interrupts(ah);
1267 ath_dbg(common, PS, "PowerSave disabled\n");
1270 void ath9k_spectral_scan_trigger(struct ieee80211_hw *hw)
1272 struct ath_softc *sc = hw->priv;
1273 struct ath_hw *ah = sc->sc_ah;
1274 struct ath_common *common = ath9k_hw_common(ah);
1277 if (config_enabled(CONFIG_ATH9K_TX99))
1280 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1281 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1285 ath9k_ps_wakeup(sc);
1286 rxfilter = ath9k_hw_getrxfilter(ah);
1287 ath9k_hw_setrxfilter(ah, rxfilter |
1288 ATH9K_RX_FILTER_PHYRADAR |
1289 ATH9K_RX_FILTER_PHYERR);
1291 /* TODO: usually this should not be neccesary, but for some reason
1292 * (or in some mode?) the trigger must be called after the
1293 * configuration, otherwise the register will have its values reset
1294 * (on my ar9220 to value 0x01002310)
1296 ath9k_spectral_scan_config(hw, sc->spectral_mode);
1297 ath9k_hw_ops(ah)->spectral_scan_trigger(ah);
1298 ath9k_ps_restore(sc);
1301 int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
1302 enum spectral_mode spectral_mode)
1304 struct ath_softc *sc = hw->priv;
1305 struct ath_hw *ah = sc->sc_ah;
1306 struct ath_common *common = ath9k_hw_common(ah);
1308 if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
1309 ath_err(common, "spectrum analyzer not implemented on this hardware\n");
1313 switch (spectral_mode) {
1314 case SPECTRAL_DISABLED:
1315 sc->spec_config.enabled = 0;
1317 case SPECTRAL_BACKGROUND:
1318 /* send endless samples.
1319 * TODO: is this really useful for "background"?
1321 sc->spec_config.endless = 1;
1322 sc->spec_config.enabled = 1;
1324 case SPECTRAL_CHANSCAN:
1325 case SPECTRAL_MANUAL:
1326 sc->spec_config.endless = 0;
1327 sc->spec_config.enabled = 1;
1333 ath9k_ps_wakeup(sc);
1334 ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
1335 ath9k_ps_restore(sc);
1337 sc->spectral_mode = spectral_mode;
1342 static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1344 struct ath_softc *sc = hw->priv;
1345 struct ath_hw *ah = sc->sc_ah;
1346 struct ath_common *common = ath9k_hw_common(ah);
1347 struct ieee80211_conf *conf = &hw->conf;
1348 struct ath_chanctx *ctx = sc->cur_chan;
1350 ath9k_ps_wakeup(sc);
1351 mutex_lock(&sc->mutex);
1353 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1354 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1356 ath_cancel_work(sc);
1357 ath9k_stop_btcoex(sc);
1359 ath9k_start_btcoex(sc);
1361 * The chip needs a reset to properly wake up from
1364 ath_chanctx_set_channel(sc, ctx, &ctx->chandef);
1369 * We just prepare to enable PS. We have to wait until our AP has
1370 * ACK'd our null data frame to disable RX otherwise we'll ignore
1371 * those ACKs and end up retransmitting the same null data frames.
1372 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1374 if (changed & IEEE80211_CONF_CHANGE_PS) {
1375 unsigned long flags;
1376 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1377 if (conf->flags & IEEE80211_CONF_PS)
1378 ath9k_enable_ps(sc);
1380 ath9k_disable_ps(sc);
1381 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1384 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1385 if (conf->flags & IEEE80211_CONF_MONITOR) {
1386 ath_dbg(common, CONFIG, "Monitor mode is enabled\n");
1387 sc->sc_ah->is_monitoring = true;
1389 ath_dbg(common, CONFIG, "Monitor mode is disabled\n");
1390 sc->sc_ah->is_monitoring = false;
1394 if (!ath9k_use_chanctx && (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
1395 ctx->offchannel = !!(conf->flags & IEEE80211_CONF_OFFCHANNEL);
1396 ath_chanctx_set_channel(sc, ctx, &hw->conf.chandef);
1399 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1400 ath_dbg(common, CONFIG, "Set power: %d\n", conf->power_level);
1401 sc->cur_chan->txpower = 2 * conf->power_level;
1402 ath9k_cmn_update_txpow(ah, sc->curtxpow,
1403 sc->cur_chan->txpower, &sc->curtxpow);
1406 mutex_unlock(&sc->mutex);
1407 ath9k_ps_restore(sc);
1412 #define SUPPORTED_FILTERS \
1413 (FIF_PROMISC_IN_BSS | \
1418 FIF_BCN_PRBRESP_PROMISC | \
1422 /* FIXME: sc->sc_full_reset ? */
1423 static void ath9k_configure_filter(struct ieee80211_hw *hw,
1424 unsigned int changed_flags,
1425 unsigned int *total_flags,
1428 struct ath_softc *sc = hw->priv;
1431 changed_flags &= SUPPORTED_FILTERS;
1432 *total_flags &= SUPPORTED_FILTERS;
1434 sc->rx.rxfilter = *total_flags;
1435 ath9k_ps_wakeup(sc);
1436 rfilt = ath_calcrxfilter(sc);
1437 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
1438 ath9k_ps_restore(sc);
1440 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG, "Set HW RX filter: 0x%x\n",
1444 static int ath9k_sta_add(struct ieee80211_hw *hw,
1445 struct ieee80211_vif *vif,
1446 struct ieee80211_sta *sta)
1448 struct ath_softc *sc = hw->priv;
1449 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1450 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1451 struct ieee80211_key_conf ps_key = { };
1454 ath_node_attach(sc, sta, vif);
1456 if (vif->type != NL80211_IFTYPE_AP &&
1457 vif->type != NL80211_IFTYPE_AP_VLAN)
1460 key = ath_key_config(common, vif, sta, &ps_key);
1463 an->key_idx[0] = key;
1469 static void ath9k_del_ps_key(struct ath_softc *sc,
1470 struct ieee80211_vif *vif,
1471 struct ieee80211_sta *sta)
1473 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1474 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1475 struct ieee80211_key_conf ps_key = { .hw_key_idx = an->ps_key };
1480 ath_key_delete(common, &ps_key);
1485 static int ath9k_sta_remove(struct ieee80211_hw *hw,
1486 struct ieee80211_vif *vif,
1487 struct ieee80211_sta *sta)
1489 struct ath_softc *sc = hw->priv;
1491 ath9k_del_ps_key(sc, vif, sta);
1492 ath_node_detach(sc, sta);
1497 static void ath9k_sta_set_tx_filter(struct ath_hw *ah,
1498 struct ath_node *an,
1503 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1504 if (!an->key_idx[i])
1506 ath9k_hw_set_tx_filter(ah, an->key_idx[i], set);
1510 static void ath9k_sta_notify(struct ieee80211_hw *hw,
1511 struct ieee80211_vif *vif,
1512 enum sta_notify_cmd cmd,
1513 struct ieee80211_sta *sta)
1515 struct ath_softc *sc = hw->priv;
1516 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1519 case STA_NOTIFY_SLEEP:
1520 an->sleeping = true;
1521 ath_tx_aggr_sleep(sta, sc, an);
1522 ath9k_sta_set_tx_filter(sc->sc_ah, an, true);
1524 case STA_NOTIFY_AWAKE:
1525 ath9k_sta_set_tx_filter(sc->sc_ah, an, false);
1526 an->sleeping = false;
1527 ath_tx_aggr_wakeup(sc, an);
1532 static int ath9k_conf_tx(struct ieee80211_hw *hw,
1533 struct ieee80211_vif *vif, u16 queue,
1534 const struct ieee80211_tx_queue_params *params)
1536 struct ath_softc *sc = hw->priv;
1537 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1538 struct ath_txq *txq;
1539 struct ath9k_tx_queue_info qi;
1542 if (queue >= IEEE80211_NUM_ACS)
1545 txq = sc->tx.txq_map[queue];
1547 ath9k_ps_wakeup(sc);
1548 mutex_lock(&sc->mutex);
1550 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1552 qi.tqi_aifs = params->aifs;
1553 qi.tqi_cwmin = params->cw_min;
1554 qi.tqi_cwmax = params->cw_max;
1555 qi.tqi_burstTime = params->txop * 32;
1557 ath_dbg(common, CONFIG,
1558 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1559 queue, txq->axq_qnum, params->aifs, params->cw_min,
1560 params->cw_max, params->txop);
1562 ath_update_max_aggr_framelen(sc, queue, qi.tqi_burstTime);
1563 ret = ath_txq_update(sc, txq->axq_qnum, &qi);
1565 ath_err(common, "TXQ Update failed\n");
1567 mutex_unlock(&sc->mutex);
1568 ath9k_ps_restore(sc);
1573 static int ath9k_set_key(struct ieee80211_hw *hw,
1574 enum set_key_cmd cmd,
1575 struct ieee80211_vif *vif,
1576 struct ieee80211_sta *sta,
1577 struct ieee80211_key_conf *key)
1579 struct ath_softc *sc = hw->priv;
1580 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1581 struct ath_node *an = NULL;
1584 if (ath9k_modparam_nohwcrypt)
1587 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1588 vif->type == NL80211_IFTYPE_MESH_POINT) &&
1589 (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
1590 key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
1591 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
1593 * For now, disable hw crypto for the RSN IBSS group keys. This
1594 * could be optimized in the future to use a modified key cache
1595 * design to support per-STA RX GTK, but until that gets
1596 * implemented, use of software crypto for group addressed
1597 * frames is a acceptable to allow RSN IBSS to be used.
1602 mutex_lock(&sc->mutex);
1603 ath9k_ps_wakeup(sc);
1604 ath_dbg(common, CONFIG, "Set HW Key %d\n", cmd);
1606 an = (struct ath_node *)sta->drv_priv;
1611 ath9k_del_ps_key(sc, vif, sta);
1613 key->hw_key_idx = 0;
1614 ret = ath_key_config(common, vif, sta, key);
1616 key->hw_key_idx = ret;
1617 /* push IV and Michael MIC generation to stack */
1618 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1619 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1620 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1621 if (sc->sc_ah->sw_mgmt_crypto &&
1622 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1623 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
1626 if (an && key->hw_key_idx) {
1627 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1630 an->key_idx[i] = key->hw_key_idx;
1633 WARN_ON(i == ARRAY_SIZE(an->key_idx));
1637 ath_key_delete(common, key);
1639 for (i = 0; i < ARRAY_SIZE(an->key_idx); i++) {
1640 if (an->key_idx[i] != key->hw_key_idx)
1646 key->hw_key_idx = 0;
1652 ath9k_ps_restore(sc);
1653 mutex_unlock(&sc->mutex);
1658 void ath9k_p2p_ps_timer(void *priv)
1660 struct ath_softc *sc = priv;
1661 struct ath_vif *avp = sc->p2p_ps_vif;
1662 struct ieee80211_vif *vif;
1663 struct ieee80211_sta *sta;
1664 struct ath_node *an;
1667 if (!avp || avp->chanctx != sc->cur_chan)
1670 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1671 if (!avp->noa.absent)
1672 tsf += ATH_P2P_PS_STOP_TIME;
1674 if (!avp->noa.has_next_tsf ||
1675 avp->noa.next_tsf - tsf > BIT(31))
1676 ieee80211_update_p2p_noa(&avp->noa, tsf);
1678 ath9k_update_p2p_ps_timer(sc, avp);
1683 sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
1687 an = (void *) sta->drv_priv;
1688 if (an->sleeping == !!avp->noa.absent)
1691 an->sleeping = avp->noa.absent;
1693 ath_tx_aggr_sleep(sta, sc, an);
1695 ath_tx_aggr_wakeup(sc, an);
1701 void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1703 struct ath_vif *avp = (void *)vif->drv_priv;
1706 if (!sc->p2p_ps_timer)
1709 if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
1712 sc->p2p_ps_vif = avp;
1713 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1714 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1715 ath9k_update_p2p_ps_timer(sc, avp);
1718 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1719 struct ieee80211_vif *vif,
1720 struct ieee80211_bss_conf *bss_conf,
1724 (BSS_CHANGED_ASSOC | \
1725 BSS_CHANGED_IBSS | \
1726 BSS_CHANGED_BEACON_ENABLED)
1728 struct ath_softc *sc = hw->priv;
1729 struct ath_hw *ah = sc->sc_ah;
1730 struct ath_common *common = ath9k_hw_common(ah);
1731 struct ath_vif *avp = (void *)vif->drv_priv;
1732 unsigned long flags;
1735 ath9k_ps_wakeup(sc);
1736 mutex_lock(&sc->mutex);
1738 if (changed & BSS_CHANGED_ASSOC) {
1739 ath_dbg(common, CONFIG, "BSSID %pM Changed ASSOC %d\n",
1740 bss_conf->bssid, bss_conf->assoc);
1742 ath9k_calculate_summary_state(sc, avp->chanctx);
1745 if (changed & BSS_CHANGED_IBSS) {
1746 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1747 common->curaid = bss_conf->aid;
1748 ath9k_hw_write_associd(sc->sc_ah);
1751 if ((changed & BSS_CHANGED_BEACON_ENABLED) ||
1752 (changed & BSS_CHANGED_BEACON_INT)) {
1753 if (changed & BSS_CHANGED_BEACON_ENABLED)
1754 ath9k_calculate_summary_state(sc, avp->chanctx);
1755 ath9k_beacon_config(sc, vif, changed);
1758 if ((avp->chanctx == sc->cur_chan) &&
1759 (changed & BSS_CHANGED_ERP_SLOT)) {
1760 if (bss_conf->use_short_slot)
1764 if (vif->type == NL80211_IFTYPE_AP) {
1766 * Defer update, so that connected stations can adjust
1767 * their settings at the same time.
1768 * See beacon.c for more details
1770 sc->beacon.slottime = slottime;
1771 sc->beacon.updateslot = UPDATE;
1773 ah->slottime = slottime;
1774 ath9k_hw_init_global_settings(ah);
1778 if (changed & BSS_CHANGED_P2P_PS) {
1779 spin_lock_bh(&sc->sc_pcu_lock);
1780 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1781 if (!(sc->ps_flags & PS_BEACON_SYNC))
1782 ath9k_update_p2p_ps(sc, vif);
1783 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1784 spin_unlock_bh(&sc->sc_pcu_lock);
1787 if (changed & CHECK_ANI)
1790 mutex_unlock(&sc->mutex);
1791 ath9k_ps_restore(sc);
1796 static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1798 struct ath_softc *sc = hw->priv;
1801 mutex_lock(&sc->mutex);
1802 ath9k_ps_wakeup(sc);
1803 tsf = ath9k_hw_gettsf64(sc->sc_ah);
1804 ath9k_ps_restore(sc);
1805 mutex_unlock(&sc->mutex);
1810 static void ath9k_set_tsf(struct ieee80211_hw *hw,
1811 struct ieee80211_vif *vif,
1814 struct ath_softc *sc = hw->priv;
1816 mutex_lock(&sc->mutex);
1817 ath9k_ps_wakeup(sc);
1818 ath9k_hw_settsf64(sc->sc_ah, tsf);
1819 ath9k_ps_restore(sc);
1820 mutex_unlock(&sc->mutex);
1823 static void ath9k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1825 struct ath_softc *sc = hw->priv;
1827 mutex_lock(&sc->mutex);
1829 ath9k_ps_wakeup(sc);
1830 ath9k_hw_reset_tsf(sc->sc_ah);
1831 ath9k_ps_restore(sc);
1833 mutex_unlock(&sc->mutex);
1836 static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1837 struct ieee80211_vif *vif,
1838 enum ieee80211_ampdu_mlme_action action,
1839 struct ieee80211_sta *sta,
1840 u16 tid, u16 *ssn, u8 buf_size)
1842 struct ath_softc *sc = hw->priv;
1846 mutex_lock(&sc->mutex);
1849 case IEEE80211_AMPDU_RX_START:
1851 case IEEE80211_AMPDU_RX_STOP:
1853 case IEEE80211_AMPDU_TX_START:
1854 ath9k_ps_wakeup(sc);
1855 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
1857 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1858 ath9k_ps_restore(sc);
1860 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1861 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1863 case IEEE80211_AMPDU_TX_STOP_CONT:
1864 ath9k_ps_wakeup(sc);
1865 ath_tx_aggr_stop(sc, sta, tid);
1867 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1868 ath9k_ps_restore(sc);
1870 case IEEE80211_AMPDU_TX_OPERATIONAL:
1871 ath9k_ps_wakeup(sc);
1872 ath_tx_aggr_resume(sc, sta, tid);
1873 ath9k_ps_restore(sc);
1876 ath_err(ath9k_hw_common(sc->sc_ah), "Unknown AMPDU action\n");
1879 mutex_unlock(&sc->mutex);
1884 static int ath9k_get_survey(struct ieee80211_hw *hw, int idx,
1885 struct survey_info *survey)
1887 struct ath_softc *sc = hw->priv;
1888 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1889 struct ieee80211_supported_band *sband;
1890 struct ieee80211_channel *chan;
1893 if (config_enabled(CONFIG_ATH9K_TX99))
1896 spin_lock_bh(&common->cc_lock);
1898 ath_update_survey_stats(sc);
1900 sband = hw->wiphy->bands[IEEE80211_BAND_2GHZ];
1901 if (sband && idx >= sband->n_channels) {
1902 idx -= sband->n_channels;
1907 sband = hw->wiphy->bands[IEEE80211_BAND_5GHZ];
1909 if (!sband || idx >= sband->n_channels) {
1910 spin_unlock_bh(&common->cc_lock);
1914 chan = &sband->channels[idx];
1915 pos = chan->hw_value;
1916 memcpy(survey, &sc->survey[pos], sizeof(*survey));
1917 survey->channel = chan;
1918 spin_unlock_bh(&common->cc_lock);
1923 static void ath9k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
1925 struct ath_softc *sc = hw->priv;
1926 struct ath_hw *ah = sc->sc_ah;
1928 if (config_enabled(CONFIG_ATH9K_TX99))
1931 mutex_lock(&sc->mutex);
1932 ah->coverage_class = coverage_class;
1934 ath9k_ps_wakeup(sc);
1935 ath9k_hw_init_global_settings(ah);
1936 ath9k_ps_restore(sc);
1938 mutex_unlock(&sc->mutex);
1941 static bool ath9k_has_tx_pending(struct ath_softc *sc)
1945 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
1946 if (!ATH_TXQ_SETUP(sc, i))
1949 if (!sc->tx.txq[i].axq_depth)
1952 npend = ath9k_has_pending_frames(sc, &sc->tx.txq[i]);
1960 static void ath9k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1961 u32 queues, bool drop)
1963 struct ath_softc *sc = hw->priv;
1965 mutex_lock(&sc->mutex);
1966 __ath9k_flush(hw, queues, drop);
1967 mutex_unlock(&sc->mutex);
1970 void __ath9k_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1972 struct ath_softc *sc = hw->priv;
1973 struct ath_hw *ah = sc->sc_ah;
1974 struct ath_common *common = ath9k_hw_common(ah);
1975 int timeout = HZ / 5; /* 200 ms */
1978 cancel_delayed_work_sync(&sc->tx_complete_work);
1980 if (ah->ah_flags & AH_UNPLUGGED) {
1981 ath_dbg(common, ANY, "Device has been unplugged!\n");
1985 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
1986 ath_dbg(common, ANY, "Device not present\n");
1990 if (wait_event_timeout(sc->tx_wait, !ath9k_has_tx_pending(sc),
1995 ath9k_ps_wakeup(sc);
1996 spin_lock_bh(&sc->sc_pcu_lock);
1997 drain_txq = ath_drain_all_txq(sc);
1998 spin_unlock_bh(&sc->sc_pcu_lock);
2003 ath9k_ps_restore(sc);
2004 ieee80211_wake_queues(hw);
2007 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
2010 static bool ath9k_tx_frames_pending(struct ieee80211_hw *hw)
2012 struct ath_softc *sc = hw->priv;
2015 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
2016 if (!ATH_TXQ_SETUP(sc, i))
2019 if (ath9k_has_pending_frames(sc, &sc->tx.txq[i]))
2025 static int ath9k_tx_last_beacon(struct ieee80211_hw *hw)
2027 struct ath_softc *sc = hw->priv;
2028 struct ath_hw *ah = sc->sc_ah;
2029 struct ieee80211_vif *vif;
2030 struct ath_vif *avp;
2032 struct ath_tx_status ts;
2033 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
2036 vif = sc->beacon.bslot[0];
2040 if (!vif->bss_conf.enable_beacon)
2043 avp = (void *)vif->drv_priv;
2045 if (!sc->beacon.tx_processed && !edma) {
2046 tasklet_disable(&sc->bcon_tasklet);
2049 if (!bf || !bf->bf_mpdu)
2052 status = ath9k_hw_txprocdesc(ah, bf->bf_desc, &ts);
2053 if (status == -EINPROGRESS)
2056 sc->beacon.tx_processed = true;
2057 sc->beacon.tx_last = !(ts.ts_status & ATH9K_TXERR_MASK);
2060 tasklet_enable(&sc->bcon_tasklet);
2063 return sc->beacon.tx_last;
2066 static int ath9k_get_stats(struct ieee80211_hw *hw,
2067 struct ieee80211_low_level_stats *stats)
2069 struct ath_softc *sc = hw->priv;
2070 struct ath_hw *ah = sc->sc_ah;
2071 struct ath9k_mib_stats *mib_stats = &ah->ah_mibStats;
2073 stats->dot11ACKFailureCount = mib_stats->ackrcv_bad;
2074 stats->dot11RTSFailureCount = mib_stats->rts_bad;
2075 stats->dot11FCSErrorCount = mib_stats->fcs_bad;
2076 stats->dot11RTSSuccessCount = mib_stats->rts_good;
2080 static u32 fill_chainmask(u32 cap, u32 new)
2085 for (i = 0; cap && new; i++, cap >>= 1) {
2086 if (!(cap & BIT(0)))
2098 static bool validate_antenna_mask(struct ath_hw *ah, u32 val)
2100 if (AR_SREV_9300_20_OR_LATER(ah))
2103 switch (val & 0x7) {
2109 return (ah->caps.rx_chainmask == 1);
2115 static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2117 struct ath_softc *sc = hw->priv;
2118 struct ath_hw *ah = sc->sc_ah;
2120 if (ah->caps.rx_chainmask != 1)
2123 if (!validate_antenna_mask(ah, rx_ant) || !tx_ant)
2126 sc->ant_rx = rx_ant;
2127 sc->ant_tx = tx_ant;
2129 if (ah->caps.rx_chainmask == 1)
2132 /* AR9100 runs into calibration issues if not all rx chains are enabled */
2133 if (AR_SREV_9100(ah))
2134 ah->rxchainmask = 0x7;
2136 ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
2138 ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
2139 ath9k_cmn_reload_chainmask(ah);
2144 static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2146 struct ath_softc *sc = hw->priv;
2148 *tx_ant = sc->ant_tx;
2149 *rx_ant = sc->ant_rx;
2153 static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
2155 struct ath_softc *sc = hw->priv;
2156 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2157 set_bit(ATH_OP_SCANNING, &common->op_flags);
2160 static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2162 struct ath_softc *sc = hw->priv;
2163 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2164 clear_bit(ATH_OP_SCANNING, &common->op_flags);
2168 ath_scan_next_channel(struct ath_softc *sc)
2170 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
2171 struct ieee80211_channel *chan;
2173 if (sc->offchannel.scan_idx >= req->n_channels) {
2174 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
2175 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
2180 chan = req->channels[sc->offchannel.scan_idx++];
2181 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND;
2182 ath_chanctx_offchan_switch(sc, chan);
2185 static void ath_offchannel_next(struct ath_softc *sc)
2187 struct ieee80211_vif *vif;
2189 if (sc->offchannel.scan_req) {
2190 vif = sc->offchannel.scan_vif;
2191 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
2192 ath_scan_next_channel(sc);
2193 } else if (sc->offchannel.roc_vif) {
2194 vif = sc->offchannel.roc_vif;
2195 sc->offchannel.chan.txpower = vif->bss_conf.txpower;
2196 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START;
2197 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan);
2199 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false),
2201 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
2203 ath_cancel_work(sc);
2207 static void ath_roc_complete(struct ath_softc *sc, bool abort)
2209 sc->offchannel.roc_vif = NULL;
2210 sc->offchannel.roc_chan = NULL;
2212 ieee80211_remain_on_channel_expired(sc->hw);
2213 ath_offchannel_next(sc);
2214 ath9k_ps_restore(sc);
2217 static void ath_scan_complete(struct ath_softc *sc, bool abort)
2219 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2221 sc->offchannel.scan_req = NULL;
2222 sc->offchannel.scan_vif = NULL;
2223 sc->offchannel.state = ATH_OFFCHANNEL_IDLE;
2224 ieee80211_scan_completed(sc->hw, abort);
2225 clear_bit(ATH_OP_SCANNING, &common->op_flags);
2226 ath_offchannel_next(sc);
2227 ath9k_ps_restore(sc);
2230 static void ath_scan_send_probe(struct ath_softc *sc,
2231 struct cfg80211_ssid *ssid)
2233 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
2234 struct ieee80211_vif *vif = sc->offchannel.scan_vif;
2235 struct ath_tx_control txctl = {};
2236 struct sk_buff *skb;
2237 struct ieee80211_tx_info *info;
2238 int band = sc->offchannel.chan.chandef.chan->band;
2240 skb = ieee80211_probereq_get(sc->hw, vif,
2241 ssid->ssid, ssid->ssid_len, req->ie_len);
2245 info = IEEE80211_SKB_CB(skb);
2247 info->flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2250 memcpy(skb_put(skb, req->ie_len), req->ie, req->ie_len);
2252 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2254 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL))
2257 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
2258 txctl.force_channel = true;
2259 if (ath_tx_start(sc->hw, skb, &txctl))
2265 ieee80211_free_txskb(sc->hw, skb);
2268 static void ath_scan_channel_start(struct ath_softc *sc)
2270 struct cfg80211_scan_request *req = sc->offchannel.scan_req;
2273 if ((sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) ||
2275 dwell = HZ / 9; /* ~110 ms */
2277 dwell = HZ / 16; /* ~60 ms */
2279 for (i = 0; i < req->n_ssids; i++)
2280 ath_scan_send_probe(sc, &req->ssids[i]);
2283 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT;
2284 mod_timer(&sc->offchannel.timer, jiffies + dwell);
2287 void ath_offchannel_channel_change(struct ath_softc *sc)
2289 switch (sc->offchannel.state) {
2290 case ATH_OFFCHANNEL_PROBE_SEND:
2291 if (!sc->offchannel.scan_req)
2294 if (sc->cur_chan->chandef.chan !=
2295 sc->offchannel.chan.chandef.chan)
2298 ath_scan_channel_start(sc);
2300 case ATH_OFFCHANNEL_IDLE:
2301 if (!sc->offchannel.scan_req)
2304 ath_scan_complete(sc, false);
2306 case ATH_OFFCHANNEL_ROC_START:
2307 if (sc->cur_chan != &sc->offchannel.chan)
2310 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT;
2311 mod_timer(&sc->offchannel.timer, jiffies +
2312 msecs_to_jiffies(sc->offchannel.roc_duration));
2313 ieee80211_ready_on_channel(sc->hw);
2315 case ATH_OFFCHANNEL_ROC_DONE:
2316 ath_roc_complete(sc, false);
2323 void ath_offchannel_timer(unsigned long data)
2325 struct ath_softc *sc = (struct ath_softc *)data;
2326 struct ath_chanctx *ctx;
2328 switch (sc->offchannel.state) {
2329 case ATH_OFFCHANNEL_PROBE_WAIT:
2330 if (!sc->offchannel.scan_req)
2333 /* get first active channel context */
2334 ctx = ath_chanctx_get_oper_chan(sc, true);
2336 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND;
2337 ath_chanctx_switch(sc, ctx, NULL);
2338 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10);
2342 case ATH_OFFCHANNEL_SUSPEND:
2343 if (!sc->offchannel.scan_req)
2346 ath_scan_next_channel(sc);
2348 case ATH_OFFCHANNEL_ROC_START:
2349 case ATH_OFFCHANNEL_ROC_WAIT:
2350 ctx = ath_chanctx_get_oper_chan(sc, false);
2351 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE;
2352 ath_chanctx_switch(sc, ctx, NULL);
2359 static int ath9k_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2360 struct cfg80211_scan_request *req)
2362 struct ath_softc *sc = hw->priv;
2363 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
2366 mutex_lock(&sc->mutex);
2368 if (WARN_ON(sc->offchannel.scan_req)) {
2373 ath9k_ps_wakeup(sc);
2374 set_bit(ATH_OP_SCANNING, &common->op_flags);
2375 sc->offchannel.scan_vif = vif;
2376 sc->offchannel.scan_req = req;
2377 sc->offchannel.scan_idx = 0;
2379 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE)
2380 ath_offchannel_next(sc);
2383 mutex_unlock(&sc->mutex);
2388 static void ath9k_cancel_hw_scan(struct ieee80211_hw *hw,
2389 struct ieee80211_vif *vif)
2391 struct ath_softc *sc = hw->priv;
2393 mutex_lock(&sc->mutex);
2394 del_timer_sync(&sc->offchannel.timer);
2395 ath_scan_complete(sc, true);
2396 mutex_unlock(&sc->mutex);
2399 static int ath9k_remain_on_channel(struct ieee80211_hw *hw,
2400 struct ieee80211_vif *vif,
2401 struct ieee80211_channel *chan, int duration,
2402 enum ieee80211_roc_type type)
2404 struct ath_softc *sc = hw->priv;
2407 mutex_lock(&sc->mutex);
2409 if (WARN_ON(sc->offchannel.roc_vif)) {
2414 ath9k_ps_wakeup(sc);
2415 sc->offchannel.roc_vif = vif;
2416 sc->offchannel.roc_chan = chan;
2417 sc->offchannel.roc_duration = duration;
2419 if (sc->offchannel.state == ATH_OFFCHANNEL_IDLE)
2420 ath_offchannel_next(sc);
2423 mutex_unlock(&sc->mutex);
2428 static int ath9k_cancel_remain_on_channel(struct ieee80211_hw *hw)
2430 struct ath_softc *sc = hw->priv;
2432 mutex_lock(&sc->mutex);
2434 del_timer_sync(&sc->offchannel.timer);
2436 if (sc->offchannel.roc_vif) {
2437 if (sc->offchannel.state >= ATH_OFFCHANNEL_ROC_START)
2438 ath_roc_complete(sc, true);
2441 mutex_unlock(&sc->mutex);
2446 static int ath9k_add_chanctx(struct ieee80211_hw *hw,
2447 struct ieee80211_chanctx_conf *conf)
2449 struct ath_softc *sc = hw->priv;
2450 struct ath_chanctx *ctx, **ptr;
2452 mutex_lock(&sc->mutex);
2454 ath_for_each_chanctx(sc, ctx) {
2458 ptr = (void *) conf->drv_priv;
2460 ctx->assigned = true;
2461 ath_chanctx_set_channel(sc, ctx, &conf->def);
2462 mutex_unlock(&sc->mutex);
2465 mutex_unlock(&sc->mutex);
2470 static void ath9k_remove_chanctx(struct ieee80211_hw *hw,
2471 struct ieee80211_chanctx_conf *conf)
2473 struct ath_softc *sc = hw->priv;
2474 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2476 mutex_lock(&sc->mutex);
2477 ctx->assigned = false;
2478 mutex_unlock(&sc->mutex);
2481 static void ath9k_change_chanctx(struct ieee80211_hw *hw,
2482 struct ieee80211_chanctx_conf *conf,
2485 struct ath_softc *sc = hw->priv;
2486 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2488 mutex_lock(&sc->mutex);
2489 ath_chanctx_set_channel(sc, ctx, &conf->def);
2490 mutex_unlock(&sc->mutex);
2493 static int ath9k_assign_vif_chanctx(struct ieee80211_hw *hw,
2494 struct ieee80211_vif *vif,
2495 struct ieee80211_chanctx_conf *conf)
2497 struct ath_softc *sc = hw->priv;
2498 struct ath_vif *avp = (void *)vif->drv_priv;
2499 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2501 mutex_lock(&sc->mutex);
2503 list_add_tail(&avp->list, &ctx->vifs);
2504 ath9k_calculate_summary_state(sc, ctx);
2505 mutex_unlock(&sc->mutex);
2510 static void ath9k_unassign_vif_chanctx(struct ieee80211_hw *hw,
2511 struct ieee80211_vif *vif,
2512 struct ieee80211_chanctx_conf *conf)
2514 struct ath_softc *sc = hw->priv;
2515 struct ath_vif *avp = (void *)vif->drv_priv;
2516 struct ath_chanctx *ctx = ath_chanctx_get(conf);
2518 mutex_lock(&sc->mutex);
2519 avp->chanctx = NULL;
2520 list_del(&avp->list);
2521 ath9k_calculate_summary_state(sc, ctx);
2522 mutex_unlock(&sc->mutex);
2525 void ath9k_fill_chanctx_ops(void)
2527 if (!ath9k_use_chanctx)
2530 ath9k_ops.hw_scan = ath9k_hw_scan;
2531 ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
2532 ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
2533 ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
2534 ath9k_ops.add_chanctx = ath9k_add_chanctx;
2535 ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
2536 ath9k_ops.change_chanctx = ath9k_change_chanctx;
2537 ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
2538 ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
2541 struct ieee80211_ops ath9k_ops = {
2543 .start = ath9k_start,
2545 .add_interface = ath9k_add_interface,
2546 .change_interface = ath9k_change_interface,
2547 .remove_interface = ath9k_remove_interface,
2548 .config = ath9k_config,
2549 .configure_filter = ath9k_configure_filter,
2550 .sta_add = ath9k_sta_add,
2551 .sta_remove = ath9k_sta_remove,
2552 .sta_notify = ath9k_sta_notify,
2553 .conf_tx = ath9k_conf_tx,
2554 .bss_info_changed = ath9k_bss_info_changed,
2555 .set_key = ath9k_set_key,
2556 .get_tsf = ath9k_get_tsf,
2557 .set_tsf = ath9k_set_tsf,
2558 .reset_tsf = ath9k_reset_tsf,
2559 .ampdu_action = ath9k_ampdu_action,
2560 .get_survey = ath9k_get_survey,
2561 .rfkill_poll = ath9k_rfkill_poll_state,
2562 .set_coverage_class = ath9k_set_coverage_class,
2563 .flush = ath9k_flush,
2564 .tx_frames_pending = ath9k_tx_frames_pending,
2565 .tx_last_beacon = ath9k_tx_last_beacon,
2566 .release_buffered_frames = ath9k_release_buffered_frames,
2567 .get_stats = ath9k_get_stats,
2568 .set_antenna = ath9k_set_antenna,
2569 .get_antenna = ath9k_get_antenna,
2571 #ifdef CONFIG_ATH9K_WOW
2572 .suspend = ath9k_suspend,
2573 .resume = ath9k_resume,
2574 .set_wakeup = ath9k_set_wakeup,
2577 #ifdef CONFIG_ATH9K_DEBUGFS
2578 .get_et_sset_count = ath9k_get_et_sset_count,
2579 .get_et_stats = ath9k_get_et_stats,
2580 .get_et_strings = ath9k_get_et_strings,
2583 #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
2584 .sta_add_debugfs = ath9k_sta_add_debugfs,
2586 .sw_scan_start = ath9k_sw_scan_start,
2587 .sw_scan_complete = ath9k_sw_scan_complete,