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 ath9k_calculate_summary_state(sc
, sc
->cur_chan
);
229 ath9k_cmn_update_txpow(ah
, sc
->curtxpow
,
230 sc
->cur_chan
->txpower
, &sc
->curtxpow
);
231 clear_bit(ATH_OP_HW_RESET
, &common
->op_flags
);
233 if (!sc
->cur_chan
->offchannel
&& start
) {
234 /* restore per chanctx TSF timer */
235 if (sc
->cur_chan
->tsf_val
) {
238 offset
= ath9k_hw_get_tsf_offset(&sc
->cur_chan
->tsf_ts
,
240 ath9k_hw_settsf64(ah
, sc
->cur_chan
->tsf_val
+ offset
);
244 if (!test_bit(ATH_OP_BEACONS
, &common
->op_flags
))
247 if (ah
->opmode
== NL80211_IFTYPE_STATION
&&
248 test_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
)) {
249 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
250 sc
->ps_flags
|= PS_BEACON_SYNC
| PS_WAIT_FOR_BEACON
;
251 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
253 ath9k_set_beacon(sc
);
256 ath_restart_work(sc
);
257 ath_txq_schedule_all(sc
);
262 ath9k_hw_set_interrupts(ah
);
263 ath9k_hw_enable_interrupts(ah
);
265 if (!ath9k_is_chanctx_enabled())
266 ieee80211_wake_queues(sc
->hw
);
268 ath9k_chanctx_wake_queues(sc
);
270 ath9k_p2p_ps_timer(sc
);
275 int ath_reset_internal(struct ath_softc
*sc
, struct ath9k_channel
*hchan
)
277 struct ath_hw
*ah
= sc
->sc_ah
;
278 struct ath_common
*common
= ath9k_hw_common(ah
);
279 struct ath9k_hw_cal_data
*caldata
= NULL
;
283 __ath_cancel_work(sc
);
285 tasklet_disable(&sc
->intr_tq
);
286 spin_lock_bh(&sc
->sc_pcu_lock
);
288 if (!sc
->cur_chan
->offchannel
) {
290 caldata
= &sc
->cur_chan
->caldata
;
298 if (!ath_prepare_reset(sc
))
301 if (ath9k_is_chanctx_enabled())
304 spin_lock_bh(&sc
->chan_lock
);
305 sc
->cur_chandef
= sc
->cur_chan
->chandef
;
306 spin_unlock_bh(&sc
->chan_lock
);
308 ath_dbg(common
, CONFIG
, "Reset to %u MHz, HT40: %d fastcc: %d\n",
309 hchan
->channel
, IS_CHAN_HT40(hchan
), fastcc
);
311 r
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
314 "Unable to reset channel, reset status %d\n", r
);
316 ath9k_hw_enable_interrupts(ah
);
317 ath9k_queue_reset(sc
, RESET_TYPE_BB_HANG
);
322 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
) &&
323 sc
->cur_chan
->offchannel
)
324 ath9k_mci_set_txpower(sc
, true, false);
326 if (!ath_complete_reset(sc
, true))
330 spin_unlock_bh(&sc
->sc_pcu_lock
);
331 tasklet_enable(&sc
->intr_tq
);
336 static void ath_node_attach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
,
337 struct ieee80211_vif
*vif
)
340 an
= (struct ath_node
*)sta
->drv_priv
;
345 memset(&an
->key_idx
, 0, sizeof(an
->key_idx
));
347 ath_tx_node_init(sc
, an
);
349 ath_dynack_node_init(sc
->sc_ah
, an
);
352 static void ath_node_detach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
)
354 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
355 ath_tx_node_cleanup(sc
, an
);
357 ath_dynack_node_deinit(sc
->sc_ah
, an
);
360 void ath9k_tasklet(unsigned long data
)
362 struct ath_softc
*sc
= (struct ath_softc
*)data
;
363 struct ath_hw
*ah
= sc
->sc_ah
;
364 struct ath_common
*common
= ath9k_hw_common(ah
);
365 enum ath_reset_type type
;
367 u32 status
= sc
->intrstatus
;
371 spin_lock(&sc
->sc_pcu_lock
);
373 if (status
& ATH9K_INT_FATAL
) {
374 type
= RESET_TYPE_FATAL_INT
;
375 ath9k_queue_reset(sc
, type
);
378 * Increment the ref. counter here so that
379 * interrupts are enabled in the reset routine.
381 atomic_inc(&ah
->intr_ref_cnt
);
382 ath_dbg(common
, RESET
, "FATAL: Skipping interrupts\n");
386 if ((ah
->config
.hw_hang_checks
& HW_BB_WATCHDOG
) &&
387 (status
& ATH9K_INT_BB_WATCHDOG
)) {
388 spin_lock(&common
->cc_lock
);
389 ath_hw_cycle_counters_update(common
);
390 ar9003_hw_bb_watchdog_dbg_info(ah
);
391 spin_unlock(&common
->cc_lock
);
393 if (ar9003_hw_bb_watchdog_check(ah
)) {
394 type
= RESET_TYPE_BB_WATCHDOG
;
395 ath9k_queue_reset(sc
, type
);
398 * Increment the ref. counter here so that
399 * interrupts are enabled in the reset routine.
401 atomic_inc(&ah
->intr_ref_cnt
);
402 ath_dbg(common
, RESET
,
403 "BB_WATCHDOG: Skipping interrupts\n");
408 if (status
& ATH9K_INT_GTT
) {
411 if ((sc
->gtt_cnt
>= MAX_GTT_CNT
) && !ath9k_hw_check_alive(ah
)) {
412 type
= RESET_TYPE_TX_GTT
;
413 ath9k_queue_reset(sc
, type
);
414 atomic_inc(&ah
->intr_ref_cnt
);
415 ath_dbg(common
, RESET
,
416 "GTT: Skipping interrupts\n");
421 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
422 if ((status
& ATH9K_INT_TSFOOR
) && sc
->ps_enabled
) {
424 * TSF sync does not look correct; remain awake to sync with
427 ath_dbg(common
, PS
, "TSFOOR - Sync with next Beacon\n");
428 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
| PS_BEACON_SYNC
;
430 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
432 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
433 rxmask
= (ATH9K_INT_RXHP
| ATH9K_INT_RXLP
| ATH9K_INT_RXEOL
|
436 rxmask
= (ATH9K_INT_RX
| ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
438 if (status
& rxmask
) {
439 /* Check for high priority Rx first */
440 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) &&
441 (status
& ATH9K_INT_RXHP
))
442 ath_rx_tasklet(sc
, 0, true);
444 ath_rx_tasklet(sc
, 0, false);
447 if (status
& ATH9K_INT_TX
) {
448 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) {
450 * For EDMA chips, TX completion is enabled for the
451 * beacon queue, so if a beacon has been transmitted
452 * successfully after a GTT interrupt, the GTT counter
453 * gets reset to zero here.
457 ath_tx_edma_tasklet(sc
);
462 wake_up(&sc
->tx_wait
);
465 if (status
& ATH9K_INT_GENTIMER
)
466 ath_gen_timer_isr(sc
->sc_ah
);
468 ath9k_btcoex_handle_interrupt(sc
, status
);
470 /* re-enable hardware interrupt */
471 ath9k_hw_enable_interrupts(ah
);
473 spin_unlock(&sc
->sc_pcu_lock
);
474 ath9k_ps_restore(sc
);
477 irqreturn_t
ath_isr(int irq
, void *dev
)
479 #define SCHED_INTR ( \
481 ATH9K_INT_BB_WATCHDOG | \
492 ATH9K_INT_GENTIMER | \
495 struct ath_softc
*sc
= dev
;
496 struct ath_hw
*ah
= sc
->sc_ah
;
497 struct ath_common
*common
= ath9k_hw_common(ah
);
498 enum ath9k_int status
;
503 * The hardware is not ready/present, don't
504 * touch anything. Note this can happen early
505 * on if the IRQ is shared.
507 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
))
510 /* shared irq, not for us */
512 if (!ath9k_hw_intrpend(ah
))
515 if (test_bit(ATH_OP_HW_RESET
, &common
->op_flags
)) {
516 ath9k_hw_kill_interrupts(ah
);
521 * Figure out the reason(s) for the interrupt. Note
522 * that the hal returns a pseudo-ISR that may include
523 * bits we haven't explicitly enabled so we mask the
524 * value to insure we only process bits we requested.
526 ath9k_hw_getisr(ah
, &status
, &sync_cause
); /* NB: clears ISR too */
527 ath9k_debug_sync_cause(sc
, sync_cause
);
528 status
&= ah
->imask
; /* discard unasked-for bits */
531 * If there are no status bits set, then this interrupt was not
532 * for me (should have been caught above).
537 /* Cache the status */
538 sc
->intrstatus
= status
;
540 if (status
& SCHED_INTR
)
544 * If a FATAL or RXORN interrupt is received, we have to reset the
547 if ((status
& ATH9K_INT_FATAL
) || ((status
& ATH9K_INT_RXORN
) &&
548 !(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)))
551 if ((ah
->config
.hw_hang_checks
& HW_BB_WATCHDOG
) &&
552 (status
& ATH9K_INT_BB_WATCHDOG
))
555 #ifdef CONFIG_ATH9K_WOW
556 if (status
& ATH9K_INT_BMISS
) {
557 if (atomic_read(&sc
->wow_sleep_proc_intr
) == 0) {
558 atomic_inc(&sc
->wow_got_bmiss_intr
);
559 atomic_dec(&sc
->wow_sleep_proc_intr
);
564 if (status
& ATH9K_INT_SWBA
)
565 tasklet_schedule(&sc
->bcon_tasklet
);
567 if (status
& ATH9K_INT_TXURN
)
568 ath9k_hw_updatetxtriglevel(ah
, true);
570 if (status
& ATH9K_INT_RXEOL
) {
571 ah
->imask
&= ~(ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
572 ath9k_hw_set_interrupts(ah
);
575 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
576 if (status
& ATH9K_INT_TIM_TIMER
) {
577 if (ATH_DBG_WARN_ON_ONCE(sc
->ps_idle
))
579 /* Clear RxAbort bit so that we can
581 ath9k_setpower(sc
, ATH9K_PM_AWAKE
);
582 spin_lock(&sc
->sc_pm_lock
);
583 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
584 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
;
585 spin_unlock(&sc
->sc_pm_lock
);
590 ath_debug_stat_interrupt(sc
, status
);
593 /* turn off every interrupt */
594 ath9k_hw_disable_interrupts(ah
);
595 tasklet_schedule(&sc
->intr_tq
);
603 int ath_reset(struct ath_softc
*sc
)
608 r
= ath_reset_internal(sc
, NULL
);
609 ath9k_ps_restore(sc
);
614 void ath9k_queue_reset(struct ath_softc
*sc
, enum ath_reset_type type
)
616 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
617 #ifdef CONFIG_ATH9K_DEBUGFS
618 RESET_STAT_INC(sc
, type
);
620 set_bit(ATH_OP_HW_RESET
, &common
->op_flags
);
621 ieee80211_queue_work(sc
->hw
, &sc
->hw_reset_work
);
624 void ath_reset_work(struct work_struct
*work
)
626 struct ath_softc
*sc
= container_of(work
, struct ath_softc
, hw_reset_work
);
631 /**********************/
632 /* mac80211 callbacks */
633 /**********************/
635 static int ath9k_start(struct ieee80211_hw
*hw
)
637 struct ath_softc
*sc
= hw
->priv
;
638 struct ath_hw
*ah
= sc
->sc_ah
;
639 struct ath_common
*common
= ath9k_hw_common(ah
);
640 struct ieee80211_channel
*curchan
= sc
->cur_chan
->chandef
.chan
;
641 struct ath_chanctx
*ctx
= sc
->cur_chan
;
642 struct ath9k_channel
*init_channel
;
645 ath_dbg(common
, CONFIG
,
646 "Starting driver with initial channel: %d MHz\n",
647 curchan
->center_freq
);
650 mutex_lock(&sc
->mutex
);
652 init_channel
= ath9k_cmn_get_channel(hw
, ah
, &ctx
->chandef
);
653 sc
->cur_chandef
= hw
->conf
.chandef
;
655 /* Reset SERDES registers */
656 ath9k_hw_configpcipowersave(ah
, false);
659 * The basic interface to setting the hardware in a good
660 * state is ``reset''. On return the hardware is known to
661 * be powered up and with interrupts disabled. This must
662 * be followed by initialization of the appropriate bits
663 * and then setup of the interrupt mask.
665 spin_lock_bh(&sc
->sc_pcu_lock
);
667 atomic_set(&ah
->intr_ref_cnt
, -1);
669 r
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
672 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
673 r
, curchan
->center_freq
);
674 ah
->reset_power_on
= false;
677 /* Setup our intr mask. */
678 ah
->imask
= ATH9K_INT_TX
| ATH9K_INT_RXEOL
|
679 ATH9K_INT_RXORN
| ATH9K_INT_FATAL
|
682 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
683 ah
->imask
|= ATH9K_INT_RXHP
|
686 ah
->imask
|= ATH9K_INT_RX
;
688 if (ah
->config
.hw_hang_checks
& HW_BB_WATCHDOG
)
689 ah
->imask
|= ATH9K_INT_BB_WATCHDOG
;
692 * Enable GTT interrupts only for AR9003/AR9004 chips
695 if (AR_SREV_9300_20_OR_LATER(ah
))
696 ah
->imask
|= ATH9K_INT_GTT
;
698 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
699 ah
->imask
|= ATH9K_INT_CST
;
703 clear_bit(ATH_OP_INVALID
, &common
->op_flags
);
704 sc
->sc_ah
->is_monitoring
= false;
706 if (!ath_complete_reset(sc
, false))
707 ah
->reset_power_on
= false;
709 if (ah
->led_pin
>= 0) {
710 ath9k_hw_cfg_output(ah
, ah
->led_pin
,
711 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
712 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 0);
716 * Reset key cache to sane defaults (all entries cleared) instead of
717 * semi-random values after suspend/resume.
719 ath9k_cmn_init_crypto(sc
->sc_ah
);
721 ath9k_hw_reset_tsf(ah
);
723 spin_unlock_bh(&sc
->sc_pcu_lock
);
725 mutex_unlock(&sc
->mutex
);
727 ath9k_ps_restore(sc
);
732 static void ath9k_tx(struct ieee80211_hw
*hw
,
733 struct ieee80211_tx_control
*control
,
736 struct ath_softc
*sc
= hw
->priv
;
737 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
738 struct ath_tx_control txctl
;
739 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
742 if (sc
->ps_enabled
) {
744 * mac80211 does not set PM field for normal data frames, so we
745 * need to update that based on the current PS mode.
747 if (ieee80211_is_data(hdr
->frame_control
) &&
748 !ieee80211_is_nullfunc(hdr
->frame_control
) &&
749 !ieee80211_has_pm(hdr
->frame_control
)) {
751 "Add PM=1 for a TX frame while in PS mode\n");
752 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
756 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_NETWORK_SLEEP
)) {
758 * We are using PS-Poll and mac80211 can request TX while in
759 * power save mode. Need to wake up hardware for the TX to be
760 * completed and if needed, also for RX of buffered frames.
763 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
764 if (!(sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
765 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
766 if (ieee80211_is_pspoll(hdr
->frame_control
)) {
768 "Sending PS-Poll to pick a buffered frame\n");
769 sc
->ps_flags
|= PS_WAIT_FOR_PSPOLL_DATA
;
771 ath_dbg(common
, PS
, "Wake up to complete TX\n");
772 sc
->ps_flags
|= PS_WAIT_FOR_TX_ACK
;
775 * The actual restore operation will happen only after
776 * the ps_flags bit is cleared. We are just dropping
777 * the ps_usecount here.
779 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
780 ath9k_ps_restore(sc
);
784 * Cannot tx while the hardware is in full sleep, it first needs a full
785 * chip reset to recover from that
787 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_FULL_SLEEP
)) {
788 ath_err(common
, "TX while HW is in FULL_SLEEP mode\n");
792 memset(&txctl
, 0, sizeof(struct ath_tx_control
));
793 txctl
.txq
= sc
->tx
.txq_map
[skb_get_queue_mapping(skb
)];
794 txctl
.sta
= control
->sta
;
796 ath_dbg(common
, XMIT
, "transmitting packet, skb: %p\n", skb
);
798 if (ath_tx_start(hw
, skb
, &txctl
) != 0) {
799 ath_dbg(common
, XMIT
, "TX failed\n");
800 TX_STAT_INC(txctl
.txq
->axq_qnum
, txfailed
);
806 ieee80211_free_txskb(hw
, skb
);
809 static void ath9k_stop(struct ieee80211_hw
*hw
)
811 struct ath_softc
*sc
= hw
->priv
;
812 struct ath_hw
*ah
= sc
->sc_ah
;
813 struct ath_common
*common
= ath9k_hw_common(ah
);
816 ath9k_deinit_channel_context(sc
);
818 mutex_lock(&sc
->mutex
);
822 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
823 ath_dbg(common
, ANY
, "Device not present\n");
824 mutex_unlock(&sc
->mutex
);
828 /* Ensure HW is awake when we try to shut it down. */
831 spin_lock_bh(&sc
->sc_pcu_lock
);
833 /* prevent tasklets to enable interrupts once we disable them */
834 ah
->imask
&= ~ATH9K_INT_GLOBAL
;
836 /* make sure h/w will not generate any interrupt
837 * before setting the invalid flag. */
838 ath9k_hw_disable_interrupts(ah
);
840 spin_unlock_bh(&sc
->sc_pcu_lock
);
842 /* we can now sync irq and kill any running tasklets, since we already
843 * disabled interrupts and not holding a spin lock */
844 synchronize_irq(sc
->irq
);
845 tasklet_kill(&sc
->intr_tq
);
846 tasklet_kill(&sc
->bcon_tasklet
);
848 prev_idle
= sc
->ps_idle
;
851 spin_lock_bh(&sc
->sc_pcu_lock
);
853 if (ah
->led_pin
>= 0) {
854 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 1);
855 ath9k_hw_cfg_gpio_input(ah
, ah
->led_pin
);
858 ath_prepare_reset(sc
);
861 dev_kfree_skb_any(sc
->rx
.frag
);
866 ah
->curchan
= ath9k_cmn_get_channel(hw
, ah
,
867 &sc
->cur_chan
->chandef
);
869 ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
870 ath9k_hw_phy_disable(ah
);
872 ath9k_hw_configpcipowersave(ah
, true);
874 spin_unlock_bh(&sc
->sc_pcu_lock
);
876 ath9k_ps_restore(sc
);
878 set_bit(ATH_OP_INVALID
, &common
->op_flags
);
879 sc
->ps_idle
= prev_idle
;
881 mutex_unlock(&sc
->mutex
);
883 ath_dbg(common
, CONFIG
, "Driver halt\n");
886 static bool ath9k_uses_beacons(int type
)
889 case NL80211_IFTYPE_AP
:
890 case NL80211_IFTYPE_ADHOC
:
891 case NL80211_IFTYPE_MESH_POINT
:
898 static void ath9k_vif_iter(struct ath9k_vif_iter_data
*iter_data
,
899 u8
*mac
, struct ieee80211_vif
*vif
)
901 struct ath_vif
*avp
= (struct ath_vif
*)vif
->drv_priv
;
904 if (iter_data
->has_hw_macaddr
) {
905 for (i
= 0; i
< ETH_ALEN
; i
++)
906 iter_data
->mask
[i
] &=
907 ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
909 memcpy(iter_data
->hw_macaddr
, mac
, ETH_ALEN
);
910 iter_data
->has_hw_macaddr
= true;
913 if (!vif
->bss_conf
.use_short_slot
)
914 iter_data
->slottime
= ATH9K_SLOT_TIME_20
;
917 case NL80211_IFTYPE_AP
:
920 case NL80211_IFTYPE_STATION
:
921 iter_data
->nstations
++;
922 if (avp
->assoc
&& !iter_data
->primary_sta
)
923 iter_data
->primary_sta
= vif
;
925 case NL80211_IFTYPE_ADHOC
:
926 iter_data
->nadhocs
++;
927 if (vif
->bss_conf
.enable_beacon
)
928 iter_data
->beacons
= true;
930 case NL80211_IFTYPE_MESH_POINT
:
931 iter_data
->nmeshes
++;
932 if (vif
->bss_conf
.enable_beacon
)
933 iter_data
->beacons
= true;
935 case NL80211_IFTYPE_WDS
:
943 static void ath9k_update_bssid_mask(struct ath_softc
*sc
,
944 struct ath_chanctx
*ctx
,
945 struct ath9k_vif_iter_data
*iter_data
)
947 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
951 if (!ath9k_is_chanctx_enabled())
954 list_for_each_entry(avp
, &ctx
->vifs
, list
) {
955 if (ctx
->nvifs_assigned
!= 1)
958 if (!avp
->vif
->p2p
|| !iter_data
->has_hw_macaddr
)
961 ether_addr_copy(common
->curbssid
, avp
->bssid
);
963 /* perm_addr will be used as the p2p device address. */
964 for (i
= 0; i
< ETH_ALEN
; i
++)
965 iter_data
->mask
[i
] &=
966 ~(iter_data
->hw_macaddr
[i
] ^
967 sc
->hw
->wiphy
->perm_addr
[i
]);
971 /* Called with sc->mutex held. */
972 void ath9k_calculate_iter_data(struct ath_softc
*sc
,
973 struct ath_chanctx
*ctx
,
974 struct ath9k_vif_iter_data
*iter_data
)
979 * Pick the MAC address of the first interface as the new hardware
980 * MAC address. The hardware will use it together with the BSSID mask
981 * when matching addresses.
983 memset(iter_data
, 0, sizeof(*iter_data
));
984 memset(&iter_data
->mask
, 0xff, ETH_ALEN
);
985 iter_data
->slottime
= ATH9K_SLOT_TIME_9
;
987 list_for_each_entry(avp
, &ctx
->vifs
, list
)
988 ath9k_vif_iter(iter_data
, avp
->vif
->addr
, avp
->vif
);
990 ath9k_update_bssid_mask(sc
, ctx
, iter_data
);
993 static void ath9k_set_assoc_state(struct ath_softc
*sc
,
994 struct ieee80211_vif
*vif
, bool changed
)
996 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
997 struct ath_vif
*avp
= (struct ath_vif
*)vif
->drv_priv
;
1000 set_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1002 ether_addr_copy(common
->curbssid
, avp
->bssid
);
1003 common
->curaid
= avp
->aid
;
1004 ath9k_hw_write_associd(sc
->sc_ah
);
1007 common
->last_rssi
= ATH_RSSI_DUMMY_MARKER
;
1008 sc
->sc_ah
->stats
.avgbrssi
= ATH_RSSI_DUMMY_MARKER
;
1010 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1011 sc
->ps_flags
|= PS_BEACON_SYNC
| PS_WAIT_FOR_BEACON
;
1012 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1015 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
))
1016 ath9k_mci_update_wlan_channels(sc
, false);
1018 ath_dbg(common
, CONFIG
,
1019 "Primary Station interface: %pM, BSSID: %pM\n",
1020 vif
->addr
, common
->curbssid
);
1023 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
1024 static void ath9k_set_offchannel_state(struct ath_softc
*sc
)
1026 struct ath_hw
*ah
= sc
->sc_ah
;
1027 struct ath_common
*common
= ath9k_hw_common(ah
);
1028 struct ieee80211_vif
*vif
= NULL
;
1030 ath9k_ps_wakeup(sc
);
1032 if (sc
->offchannel
.state
< ATH_OFFCHANNEL_ROC_START
)
1033 vif
= sc
->offchannel
.scan_vif
;
1035 vif
= sc
->offchannel
.roc_vif
;
1040 eth_zero_addr(common
->curbssid
);
1041 eth_broadcast_addr(common
->bssidmask
);
1042 ether_addr_copy(common
->macaddr
, vif
->addr
);
1044 ah
->opmode
= vif
->type
;
1045 ah
->imask
&= ~ATH9K_INT_SWBA
;
1046 ah
->imask
&= ~ATH9K_INT_TSFOOR
;
1047 ah
->slottime
= ATH9K_SLOT_TIME_9
;
1049 ath_hw_setbssidmask(common
);
1050 ath9k_hw_setopmode(ah
);
1051 ath9k_hw_write_associd(sc
->sc_ah
);
1052 ath9k_hw_set_interrupts(ah
);
1053 ath9k_hw_init_global_settings(ah
);
1056 ath9k_ps_restore(sc
);
1060 /* Called with sc->mutex held. */
1061 void ath9k_calculate_summary_state(struct ath_softc
*sc
,
1062 struct ath_chanctx
*ctx
)
1064 struct ath_hw
*ah
= sc
->sc_ah
;
1065 struct ath_common
*common
= ath9k_hw_common(ah
);
1066 struct ath9k_vif_iter_data iter_data
;
1067 struct ath_beacon_config
*cur_conf
;
1069 ath_chanctx_check_active(sc
, ctx
);
1071 if (ctx
!= sc
->cur_chan
)
1074 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
1075 if (ctx
== &sc
->offchannel
.chan
)
1076 return ath9k_set_offchannel_state(sc
);
1079 ath9k_ps_wakeup(sc
);
1080 ath9k_calculate_iter_data(sc
, ctx
, &iter_data
);
1082 if (iter_data
.has_hw_macaddr
)
1083 ether_addr_copy(common
->macaddr
, iter_data
.hw_macaddr
);
1085 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
1086 ath_hw_setbssidmask(common
);
1088 if (iter_data
.naps
> 0) {
1089 cur_conf
= &ctx
->beacon
;
1090 ath9k_hw_set_tsfadjust(ah
, true);
1091 ah
->opmode
= NL80211_IFTYPE_AP
;
1092 if (cur_conf
->enable_beacon
)
1093 iter_data
.beacons
= true;
1095 ath9k_hw_set_tsfadjust(ah
, false);
1097 if (iter_data
.nmeshes
)
1098 ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
1099 else if (iter_data
.nwds
)
1100 ah
->opmode
= NL80211_IFTYPE_AP
;
1101 else if (iter_data
.nadhocs
)
1102 ah
->opmode
= NL80211_IFTYPE_ADHOC
;
1104 ah
->opmode
= NL80211_IFTYPE_STATION
;
1107 ath9k_hw_setopmode(ah
);
1109 ctx
->switch_after_beacon
= false;
1110 if ((iter_data
.nstations
+ iter_data
.nadhocs
+ iter_data
.nmeshes
) > 0)
1111 ah
->imask
|= ATH9K_INT_TSFOOR
;
1113 ah
->imask
&= ~ATH9K_INT_TSFOOR
;
1114 if (iter_data
.naps
== 1 && iter_data
.beacons
)
1115 ctx
->switch_after_beacon
= true;
1118 ah
->imask
&= ~ATH9K_INT_SWBA
;
1119 if (ah
->opmode
== NL80211_IFTYPE_STATION
) {
1120 bool changed
= (iter_data
.primary_sta
!= ctx
->primary_sta
);
1122 if (iter_data
.primary_sta
) {
1123 iter_data
.beacons
= true;
1124 ath9k_set_assoc_state(sc
, iter_data
.primary_sta
,
1126 ctx
->primary_sta
= iter_data
.primary_sta
;
1128 ctx
->primary_sta
= NULL
;
1129 memset(common
->curbssid
, 0, ETH_ALEN
);
1131 ath9k_hw_write_associd(sc
->sc_ah
);
1132 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
))
1133 ath9k_mci_update_wlan_channels(sc
, true);
1135 } else if (iter_data
.beacons
) {
1136 ah
->imask
|= ATH9K_INT_SWBA
;
1138 ath9k_hw_set_interrupts(ah
);
1140 if (iter_data
.beacons
)
1141 set_bit(ATH_OP_BEACONS
, &common
->op_flags
);
1143 clear_bit(ATH_OP_BEACONS
, &common
->op_flags
);
1145 if (ah
->slottime
!= iter_data
.slottime
) {
1146 ah
->slottime
= iter_data
.slottime
;
1147 ath9k_hw_init_global_settings(ah
);
1150 if (iter_data
.primary_sta
)
1151 set_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1153 clear_bit(ATH_OP_PRIM_STA_VIF
, &common
->op_flags
);
1155 ath_dbg(common
, CONFIG
,
1156 "macaddr: %pM, bssid: %pM, bssidmask: %pM\n",
1157 common
->macaddr
, common
->curbssid
, common
->bssidmask
);
1159 ath9k_ps_restore(sc
);
1162 static void ath9k_assign_hw_queues(struct ieee80211_hw
*hw
,
1163 struct ieee80211_vif
*vif
)
1167 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1168 vif
->hw_queue
[i
] = i
;
1170 if (vif
->type
== NL80211_IFTYPE_AP
)
1171 vif
->cab_queue
= hw
->queues
- 2;
1173 vif
->cab_queue
= IEEE80211_INVAL_HW_QUEUE
;
1176 static int ath9k_add_interface(struct ieee80211_hw
*hw
,
1177 struct ieee80211_vif
*vif
)
1179 struct ath_softc
*sc
= hw
->priv
;
1180 struct ath_hw
*ah
= sc
->sc_ah
;
1181 struct ath_common
*common
= ath9k_hw_common(ah
);
1182 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1183 struct ath_node
*an
= &avp
->mcast_node
;
1185 mutex_lock(&sc
->mutex
);
1187 if (config_enabled(CONFIG_ATH9K_TX99
)) {
1188 if (sc
->cur_chan
->nvifs
>= 1) {
1189 mutex_unlock(&sc
->mutex
);
1195 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d\n", vif
->type
);
1196 sc
->cur_chan
->nvifs
++;
1198 if (ath9k_uses_beacons(vif
->type
))
1199 ath9k_beacon_assign_slot(sc
, vif
);
1202 if (!ath9k_is_chanctx_enabled()) {
1203 avp
->chanctx
= sc
->cur_chan
;
1204 list_add_tail(&avp
->list
, &avp
->chanctx
->vifs
);
1207 ath9k_assign_hw_queues(hw
, vif
);
1212 an
->no_ps_filter
= true;
1213 ath_tx_node_init(sc
, an
);
1215 mutex_unlock(&sc
->mutex
);
1219 static int ath9k_change_interface(struct ieee80211_hw
*hw
,
1220 struct ieee80211_vif
*vif
,
1221 enum nl80211_iftype new_type
,
1224 struct ath_softc
*sc
= hw
->priv
;
1225 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1226 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1228 mutex_lock(&sc
->mutex
);
1230 if (config_enabled(CONFIG_ATH9K_TX99
)) {
1231 mutex_unlock(&sc
->mutex
);
1235 ath_dbg(common
, CONFIG
, "Change Interface\n");
1237 if (ath9k_uses_beacons(vif
->type
))
1238 ath9k_beacon_remove_slot(sc
, vif
);
1240 vif
->type
= new_type
;
1243 if (ath9k_uses_beacons(vif
->type
))
1244 ath9k_beacon_assign_slot(sc
, vif
);
1246 ath9k_assign_hw_queues(hw
, vif
);
1247 ath9k_calculate_summary_state(sc
, avp
->chanctx
);
1249 mutex_unlock(&sc
->mutex
);
1253 static void ath9k_remove_interface(struct ieee80211_hw
*hw
,
1254 struct ieee80211_vif
*vif
)
1256 struct ath_softc
*sc
= hw
->priv
;
1257 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1258 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1260 ath_dbg(common
, CONFIG
, "Detach Interface\n");
1262 mutex_lock(&sc
->mutex
);
1264 ath9k_p2p_remove_vif(sc
, vif
);
1266 sc
->cur_chan
->nvifs
--;
1267 sc
->tx99_vif
= NULL
;
1268 if (!ath9k_is_chanctx_enabled())
1269 list_del(&avp
->list
);
1271 if (ath9k_uses_beacons(vif
->type
))
1272 ath9k_beacon_remove_slot(sc
, vif
);
1274 ath_tx_node_cleanup(sc
, &avp
->mcast_node
);
1276 mutex_unlock(&sc
->mutex
);
1279 static void ath9k_enable_ps(struct ath_softc
*sc
)
1281 struct ath_hw
*ah
= sc
->sc_ah
;
1282 struct ath_common
*common
= ath9k_hw_common(ah
);
1284 if (config_enabled(CONFIG_ATH9K_TX99
))
1287 sc
->ps_enabled
= true;
1288 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
1289 if ((ah
->imask
& ATH9K_INT_TIM_TIMER
) == 0) {
1290 ah
->imask
|= ATH9K_INT_TIM_TIMER
;
1291 ath9k_hw_set_interrupts(ah
);
1293 ath9k_hw_setrxabort(ah
, 1);
1295 ath_dbg(common
, PS
, "PowerSave enabled\n");
1298 static void ath9k_disable_ps(struct ath_softc
*sc
)
1300 struct ath_hw
*ah
= sc
->sc_ah
;
1301 struct ath_common
*common
= ath9k_hw_common(ah
);
1303 if (config_enabled(CONFIG_ATH9K_TX99
))
1306 sc
->ps_enabled
= false;
1307 ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
);
1308 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
1309 ath9k_hw_setrxabort(ah
, 0);
1310 sc
->ps_flags
&= ~(PS_WAIT_FOR_BEACON
|
1312 PS_WAIT_FOR_PSPOLL_DATA
|
1313 PS_WAIT_FOR_TX_ACK
);
1314 if (ah
->imask
& ATH9K_INT_TIM_TIMER
) {
1315 ah
->imask
&= ~ATH9K_INT_TIM_TIMER
;
1316 ath9k_hw_set_interrupts(ah
);
1319 ath_dbg(common
, PS
, "PowerSave disabled\n");
1322 void ath9k_spectral_scan_trigger(struct ieee80211_hw
*hw
)
1324 struct ath_softc
*sc
= hw
->priv
;
1325 struct ath_hw
*ah
= sc
->sc_ah
;
1326 struct ath_common
*common
= ath9k_hw_common(ah
);
1329 if (config_enabled(CONFIG_ATH9K_TX99
))
1332 if (!ath9k_hw_ops(ah
)->spectral_scan_trigger
) {
1333 ath_err(common
, "spectrum analyzer not implemented on this hardware\n");
1337 ath9k_ps_wakeup(sc
);
1338 rxfilter
= ath9k_hw_getrxfilter(ah
);
1339 ath9k_hw_setrxfilter(ah
, rxfilter
|
1340 ATH9K_RX_FILTER_PHYRADAR
|
1341 ATH9K_RX_FILTER_PHYERR
);
1343 /* TODO: usually this should not be neccesary, but for some reason
1344 * (or in some mode?) the trigger must be called after the
1345 * configuration, otherwise the register will have its values reset
1346 * (on my ar9220 to value 0x01002310)
1348 ath9k_spectral_scan_config(hw
, sc
->spectral_mode
);
1349 ath9k_hw_ops(ah
)->spectral_scan_trigger(ah
);
1350 ath9k_ps_restore(sc
);
1353 int ath9k_spectral_scan_config(struct ieee80211_hw
*hw
,
1354 enum spectral_mode spectral_mode
)
1356 struct ath_softc
*sc
= hw
->priv
;
1357 struct ath_hw
*ah
= sc
->sc_ah
;
1358 struct ath_common
*common
= ath9k_hw_common(ah
);
1360 if (!ath9k_hw_ops(ah
)->spectral_scan_trigger
) {
1361 ath_err(common
, "spectrum analyzer not implemented on this hardware\n");
1365 switch (spectral_mode
) {
1366 case SPECTRAL_DISABLED
:
1367 sc
->spec_config
.enabled
= 0;
1369 case SPECTRAL_BACKGROUND
:
1370 /* send endless samples.
1371 * TODO: is this really useful for "background"?
1373 sc
->spec_config
.endless
= 1;
1374 sc
->spec_config
.enabled
= 1;
1376 case SPECTRAL_CHANSCAN
:
1377 case SPECTRAL_MANUAL
:
1378 sc
->spec_config
.endless
= 0;
1379 sc
->spec_config
.enabled
= 1;
1385 ath9k_ps_wakeup(sc
);
1386 ath9k_hw_ops(ah
)->spectral_scan_config(ah
, &sc
->spec_config
);
1387 ath9k_ps_restore(sc
);
1389 sc
->spectral_mode
= spectral_mode
;
1394 static int ath9k_config(struct ieee80211_hw
*hw
, u32 changed
)
1396 struct ath_softc
*sc
= hw
->priv
;
1397 struct ath_hw
*ah
= sc
->sc_ah
;
1398 struct ath_common
*common
= ath9k_hw_common(ah
);
1399 struct ieee80211_conf
*conf
= &hw
->conf
;
1400 struct ath_chanctx
*ctx
= sc
->cur_chan
;
1402 ath9k_ps_wakeup(sc
);
1403 mutex_lock(&sc
->mutex
);
1405 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1406 sc
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1408 ath_cancel_work(sc
);
1409 ath9k_stop_btcoex(sc
);
1411 ath9k_start_btcoex(sc
);
1413 * The chip needs a reset to properly wake up from
1416 ath_chanctx_set_channel(sc
, ctx
, &ctx
->chandef
);
1421 * We just prepare to enable PS. We have to wait until our AP has
1422 * ACK'd our null data frame to disable RX otherwise we'll ignore
1423 * those ACKs and end up retransmitting the same null data frames.
1424 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1426 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1427 unsigned long flags
;
1428 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1429 if (conf
->flags
& IEEE80211_CONF_PS
)
1430 ath9k_enable_ps(sc
);
1432 ath9k_disable_ps(sc
);
1433 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1436 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1437 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1438 ath_dbg(common
, CONFIG
, "Monitor mode is enabled\n");
1439 sc
->sc_ah
->is_monitoring
= true;
1441 ath_dbg(common
, CONFIG
, "Monitor mode is disabled\n");
1442 sc
->sc_ah
->is_monitoring
= false;
1446 if (!ath9k_is_chanctx_enabled() && (changed
& IEEE80211_CONF_CHANGE_CHANNEL
)) {
1447 ctx
->offchannel
= !!(conf
->flags
& IEEE80211_CONF_OFFCHANNEL
);
1448 ath_chanctx_set_channel(sc
, ctx
, &hw
->conf
.chandef
);
1451 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1452 ath_dbg(common
, CONFIG
, "Set power: %d\n", conf
->power_level
);
1453 sc
->cur_chan
->txpower
= 2 * conf
->power_level
;
1454 ath9k_cmn_update_txpow(ah
, sc
->curtxpow
,
1455 sc
->cur_chan
->txpower
, &sc
->curtxpow
);
1458 mutex_unlock(&sc
->mutex
);
1459 ath9k_ps_restore(sc
);
1464 #define SUPPORTED_FILTERS \
1465 (FIF_PROMISC_IN_BSS | \
1470 FIF_BCN_PRBRESP_PROMISC | \
1474 /* FIXME: sc->sc_full_reset ? */
1475 static void ath9k_configure_filter(struct ieee80211_hw
*hw
,
1476 unsigned int changed_flags
,
1477 unsigned int *total_flags
,
1480 struct ath_softc
*sc
= hw
->priv
;
1483 changed_flags
&= SUPPORTED_FILTERS
;
1484 *total_flags
&= SUPPORTED_FILTERS
;
1486 spin_lock_bh(&sc
->chan_lock
);
1487 sc
->cur_chan
->rxfilter
= *total_flags
;
1488 spin_unlock_bh(&sc
->chan_lock
);
1490 ath9k_ps_wakeup(sc
);
1491 rfilt
= ath_calcrxfilter(sc
);
1492 ath9k_hw_setrxfilter(sc
->sc_ah
, rfilt
);
1493 ath9k_ps_restore(sc
);
1495 ath_dbg(ath9k_hw_common(sc
->sc_ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1499 static int ath9k_sta_add(struct ieee80211_hw
*hw
,
1500 struct ieee80211_vif
*vif
,
1501 struct ieee80211_sta
*sta
)
1503 struct ath_softc
*sc
= hw
->priv
;
1504 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1505 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1506 struct ieee80211_key_conf ps_key
= { };
1509 ath_node_attach(sc
, sta
, vif
);
1511 if (vif
->type
!= NL80211_IFTYPE_AP
&&
1512 vif
->type
!= NL80211_IFTYPE_AP_VLAN
)
1515 key
= ath_key_config(common
, vif
, sta
, &ps_key
);
1518 an
->key_idx
[0] = key
;
1524 static void ath9k_del_ps_key(struct ath_softc
*sc
,
1525 struct ieee80211_vif
*vif
,
1526 struct ieee80211_sta
*sta
)
1528 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1529 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1530 struct ieee80211_key_conf ps_key
= { .hw_key_idx
= an
->ps_key
};
1535 ath_key_delete(common
, &ps_key
);
1540 static int ath9k_sta_remove(struct ieee80211_hw
*hw
,
1541 struct ieee80211_vif
*vif
,
1542 struct ieee80211_sta
*sta
)
1544 struct ath_softc
*sc
= hw
->priv
;
1546 ath9k_del_ps_key(sc
, vif
, sta
);
1547 ath_node_detach(sc
, sta
);
1552 static void ath9k_sta_set_tx_filter(struct ath_hw
*ah
,
1553 struct ath_node
*an
,
1558 for (i
= 0; i
< ARRAY_SIZE(an
->key_idx
); i
++) {
1559 if (!an
->key_idx
[i
])
1561 ath9k_hw_set_tx_filter(ah
, an
->key_idx
[i
], set
);
1565 static void ath9k_sta_notify(struct ieee80211_hw
*hw
,
1566 struct ieee80211_vif
*vif
,
1567 enum sta_notify_cmd cmd
,
1568 struct ieee80211_sta
*sta
)
1570 struct ath_softc
*sc
= hw
->priv
;
1571 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1574 case STA_NOTIFY_SLEEP
:
1575 an
->sleeping
= true;
1576 ath_tx_aggr_sleep(sta
, sc
, an
);
1577 ath9k_sta_set_tx_filter(sc
->sc_ah
, an
, true);
1579 case STA_NOTIFY_AWAKE
:
1580 ath9k_sta_set_tx_filter(sc
->sc_ah
, an
, false);
1581 an
->sleeping
= false;
1582 ath_tx_aggr_wakeup(sc
, an
);
1587 static int ath9k_conf_tx(struct ieee80211_hw
*hw
,
1588 struct ieee80211_vif
*vif
, u16 queue
,
1589 const struct ieee80211_tx_queue_params
*params
)
1591 struct ath_softc
*sc
= hw
->priv
;
1592 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1593 struct ath_txq
*txq
;
1594 struct ath9k_tx_queue_info qi
;
1597 if (queue
>= IEEE80211_NUM_ACS
)
1600 txq
= sc
->tx
.txq_map
[queue
];
1602 ath9k_ps_wakeup(sc
);
1603 mutex_lock(&sc
->mutex
);
1605 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1607 qi
.tqi_aifs
= params
->aifs
;
1608 qi
.tqi_cwmin
= params
->cw_min
;
1609 qi
.tqi_cwmax
= params
->cw_max
;
1610 qi
.tqi_burstTime
= params
->txop
* 32;
1612 ath_dbg(common
, CONFIG
,
1613 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1614 queue
, txq
->axq_qnum
, params
->aifs
, params
->cw_min
,
1615 params
->cw_max
, params
->txop
);
1617 ath_update_max_aggr_framelen(sc
, queue
, qi
.tqi_burstTime
);
1618 ret
= ath_txq_update(sc
, txq
->axq_qnum
, &qi
);
1620 ath_err(common
, "TXQ Update failed\n");
1622 mutex_unlock(&sc
->mutex
);
1623 ath9k_ps_restore(sc
);
1628 static int ath9k_set_key(struct ieee80211_hw
*hw
,
1629 enum set_key_cmd cmd
,
1630 struct ieee80211_vif
*vif
,
1631 struct ieee80211_sta
*sta
,
1632 struct ieee80211_key_conf
*key
)
1634 struct ath_softc
*sc
= hw
->priv
;
1635 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1636 struct ath_node
*an
= NULL
;
1639 if (ath9k_modparam_nohwcrypt
)
1642 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1643 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1644 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1645 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1646 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1648 * For now, disable hw crypto for the RSN IBSS group keys. This
1649 * could be optimized in the future to use a modified key cache
1650 * design to support per-STA RX GTK, but until that gets
1651 * implemented, use of software crypto for group addressed
1652 * frames is a acceptable to allow RSN IBSS to be used.
1657 mutex_lock(&sc
->mutex
);
1658 ath9k_ps_wakeup(sc
);
1659 ath_dbg(common
, CONFIG
, "Set HW Key %d\n", cmd
);
1661 an
= (struct ath_node
*)sta
->drv_priv
;
1666 ath9k_del_ps_key(sc
, vif
, sta
);
1668 key
->hw_key_idx
= 0;
1669 ret
= ath_key_config(common
, vif
, sta
, key
);
1671 key
->hw_key_idx
= ret
;
1672 /* push IV and Michael MIC generation to stack */
1673 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1674 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1675 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1676 if (sc
->sc_ah
->sw_mgmt_crypto
&&
1677 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1678 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1681 if (an
&& key
->hw_key_idx
) {
1682 for (i
= 0; i
< ARRAY_SIZE(an
->key_idx
); i
++) {
1685 an
->key_idx
[i
] = key
->hw_key_idx
;
1688 WARN_ON(i
== ARRAY_SIZE(an
->key_idx
));
1692 ath_key_delete(common
, key
);
1694 for (i
= 0; i
< ARRAY_SIZE(an
->key_idx
); i
++) {
1695 if (an
->key_idx
[i
] != key
->hw_key_idx
)
1701 key
->hw_key_idx
= 0;
1707 ath9k_ps_restore(sc
);
1708 mutex_unlock(&sc
->mutex
);
1713 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
1714 struct ieee80211_vif
*vif
,
1715 struct ieee80211_bss_conf
*bss_conf
,
1719 (BSS_CHANGED_ASSOC | \
1720 BSS_CHANGED_IBSS | \
1721 BSS_CHANGED_BEACON_ENABLED)
1723 struct ath_softc
*sc
= hw
->priv
;
1724 struct ath_hw
*ah
= sc
->sc_ah
;
1725 struct ath_common
*common
= ath9k_hw_common(ah
);
1726 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1729 ath9k_ps_wakeup(sc
);
1730 mutex_lock(&sc
->mutex
);
1732 if (changed
& BSS_CHANGED_ASSOC
) {
1733 ath_dbg(common
, CONFIG
, "BSSID %pM Changed ASSOC %d\n",
1734 bss_conf
->bssid
, bss_conf
->assoc
);
1736 ether_addr_copy(avp
->bssid
, bss_conf
->bssid
);
1737 avp
->aid
= bss_conf
->aid
;
1738 avp
->assoc
= bss_conf
->assoc
;
1740 ath9k_calculate_summary_state(sc
, avp
->chanctx
);
1742 if (ath9k_is_chanctx_enabled()) {
1743 if (bss_conf
->assoc
)
1744 ath_chanctx_event(sc
, vif
,
1745 ATH_CHANCTX_EVENT_ASSOC
);
1749 if (changed
& BSS_CHANGED_IBSS
) {
1750 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1751 common
->curaid
= bss_conf
->aid
;
1752 ath9k_hw_write_associd(sc
->sc_ah
);
1755 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) ||
1756 (changed
& BSS_CHANGED_BEACON_INT
) ||
1757 (changed
& BSS_CHANGED_BEACON_INFO
)) {
1758 ath9k_beacon_config(sc
, vif
, changed
);
1759 if (changed
& BSS_CHANGED_BEACON_ENABLED
)
1760 ath9k_calculate_summary_state(sc
, avp
->chanctx
);
1763 if ((avp
->chanctx
== sc
->cur_chan
) &&
1764 (changed
& BSS_CHANGED_ERP_SLOT
)) {
1765 if (bss_conf
->use_short_slot
)
1769 if (vif
->type
== NL80211_IFTYPE_AP
) {
1771 * Defer update, so that connected stations can adjust
1772 * their settings at the same time.
1773 * See beacon.c for more details
1775 sc
->beacon
.slottime
= slottime
;
1776 sc
->beacon
.updateslot
= UPDATE
;
1778 ah
->slottime
= slottime
;
1779 ath9k_hw_init_global_settings(ah
);
1783 if (changed
& BSS_CHANGED_P2P_PS
)
1784 ath9k_p2p_bss_info_changed(sc
, vif
);
1786 if (changed
& CHECK_ANI
)
1789 mutex_unlock(&sc
->mutex
);
1790 ath9k_ps_restore(sc
);
1795 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1797 struct ath_softc
*sc
= hw
->priv
;
1800 mutex_lock(&sc
->mutex
);
1801 ath9k_ps_wakeup(sc
);
1802 tsf
= ath9k_hw_gettsf64(sc
->sc_ah
);
1803 ath9k_ps_restore(sc
);
1804 mutex_unlock(&sc
->mutex
);
1809 static void ath9k_set_tsf(struct ieee80211_hw
*hw
,
1810 struct ieee80211_vif
*vif
,
1813 struct ath_softc
*sc
= hw
->priv
;
1815 mutex_lock(&sc
->mutex
);
1816 ath9k_ps_wakeup(sc
);
1817 ath9k_hw_settsf64(sc
->sc_ah
, tsf
);
1818 ath9k_ps_restore(sc
);
1819 mutex_unlock(&sc
->mutex
);
1822 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1824 struct ath_softc
*sc
= hw
->priv
;
1826 mutex_lock(&sc
->mutex
);
1828 ath9k_ps_wakeup(sc
);
1829 ath9k_hw_reset_tsf(sc
->sc_ah
);
1830 ath9k_ps_restore(sc
);
1832 mutex_unlock(&sc
->mutex
);
1835 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
1836 struct ieee80211_vif
*vif
,
1837 enum ieee80211_ampdu_mlme_action action
,
1838 struct ieee80211_sta
*sta
,
1839 u16 tid
, u16
*ssn
, u8 buf_size
)
1841 struct ath_softc
*sc
= hw
->priv
;
1845 mutex_lock(&sc
->mutex
);
1848 case IEEE80211_AMPDU_RX_START
:
1850 case IEEE80211_AMPDU_RX_STOP
:
1852 case IEEE80211_AMPDU_TX_START
:
1853 ath9k_ps_wakeup(sc
);
1854 ret
= ath_tx_aggr_start(sc
, sta
, tid
, ssn
);
1856 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1857 ath9k_ps_restore(sc
);
1859 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1860 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1862 case IEEE80211_AMPDU_TX_STOP_CONT
:
1863 ath9k_ps_wakeup(sc
);
1864 ath_tx_aggr_stop(sc
, sta
, tid
);
1866 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1867 ath9k_ps_restore(sc
);
1869 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1870 ath9k_ps_wakeup(sc
);
1871 ath_tx_aggr_resume(sc
, sta
, tid
);
1872 ath9k_ps_restore(sc
);
1875 ath_err(ath9k_hw_common(sc
->sc_ah
), "Unknown AMPDU action\n");
1878 mutex_unlock(&sc
->mutex
);
1883 static int ath9k_get_survey(struct ieee80211_hw
*hw
, int idx
,
1884 struct survey_info
*survey
)
1886 struct ath_softc
*sc
= hw
->priv
;
1887 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1888 struct ieee80211_supported_band
*sband
;
1889 struct ieee80211_channel
*chan
;
1892 if (config_enabled(CONFIG_ATH9K_TX99
))
1895 spin_lock_bh(&common
->cc_lock
);
1897 ath_update_survey_stats(sc
);
1899 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
1900 if (sband
&& idx
>= sband
->n_channels
) {
1901 idx
-= sband
->n_channels
;
1906 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
1908 if (!sband
|| idx
>= sband
->n_channels
) {
1909 spin_unlock_bh(&common
->cc_lock
);
1913 chan
= &sband
->channels
[idx
];
1914 pos
= chan
->hw_value
;
1915 memcpy(survey
, &sc
->survey
[pos
], sizeof(*survey
));
1916 survey
->channel
= chan
;
1917 spin_unlock_bh(&common
->cc_lock
);
1922 static void ath9k_enable_dynack(struct ath_softc
*sc
)
1924 #ifdef CONFIG_ATH9K_DYNACK
1926 struct ath_hw
*ah
= sc
->sc_ah
;
1928 ath_dynack_reset(ah
);
1930 ah
->dynack
.enabled
= true;
1931 rfilt
= ath_calcrxfilter(sc
);
1932 ath9k_hw_setrxfilter(ah
, rfilt
);
1936 static void ath9k_set_coverage_class(struct ieee80211_hw
*hw
,
1939 struct ath_softc
*sc
= hw
->priv
;
1940 struct ath_hw
*ah
= sc
->sc_ah
;
1942 if (config_enabled(CONFIG_ATH9K_TX99
))
1945 mutex_lock(&sc
->mutex
);
1947 if (coverage_class
>= 0) {
1948 ah
->coverage_class
= coverage_class
;
1949 if (ah
->dynack
.enabled
) {
1952 ah
->dynack
.enabled
= false;
1953 rfilt
= ath_calcrxfilter(sc
);
1954 ath9k_hw_setrxfilter(ah
, rfilt
);
1956 ath9k_ps_wakeup(sc
);
1957 ath9k_hw_init_global_settings(ah
);
1958 ath9k_ps_restore(sc
);
1959 } else if (!ah
->dynack
.enabled
) {
1960 ath9k_enable_dynack(sc
);
1963 mutex_unlock(&sc
->mutex
);
1966 static bool ath9k_has_tx_pending(struct ath_softc
*sc
)
1970 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1971 if (!ATH_TXQ_SETUP(sc
, i
))
1974 if (!sc
->tx
.txq
[i
].axq_depth
)
1977 npend
= ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]);
1985 static void ath9k_flush(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1986 u32 queues
, bool drop
)
1988 struct ath_softc
*sc
= hw
->priv
;
1990 mutex_lock(&sc
->mutex
);
1991 __ath9k_flush(hw
, queues
, drop
);
1992 mutex_unlock(&sc
->mutex
);
1995 void __ath9k_flush(struct ieee80211_hw
*hw
, u32 queues
, bool drop
)
1997 struct ath_softc
*sc
= hw
->priv
;
1998 struct ath_hw
*ah
= sc
->sc_ah
;
1999 struct ath_common
*common
= ath9k_hw_common(ah
);
2000 int timeout
= HZ
/ 5; /* 200 ms */
2004 cancel_delayed_work_sync(&sc
->tx_complete_work
);
2006 if (ah
->ah_flags
& AH_UNPLUGGED
) {
2007 ath_dbg(common
, ANY
, "Device has been unplugged!\n");
2011 if (test_bit(ATH_OP_INVALID
, &common
->op_flags
)) {
2012 ath_dbg(common
, ANY
, "Device not present\n");
2016 if (wait_event_timeout(sc
->tx_wait
, !ath9k_has_tx_pending(sc
),
2021 ath9k_ps_wakeup(sc
);
2022 spin_lock_bh(&sc
->sc_pcu_lock
);
2023 drain_txq
= ath_drain_all_txq(sc
);
2024 spin_unlock_bh(&sc
->sc_pcu_lock
);
2029 ath9k_ps_restore(sc
);
2030 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
2031 ieee80211_wake_queue(sc
->hw
,
2032 sc
->cur_chan
->hw_queue_base
+ i
);
2036 ieee80211_queue_delayed_work(hw
, &sc
->tx_complete_work
, 0);
2039 static bool ath9k_tx_frames_pending(struct ieee80211_hw
*hw
)
2041 struct ath_softc
*sc
= hw
->priv
;
2044 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
2045 if (!ATH_TXQ_SETUP(sc
, i
))
2048 if (ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]))
2054 static int ath9k_tx_last_beacon(struct ieee80211_hw
*hw
)
2056 struct ath_softc
*sc
= hw
->priv
;
2057 struct ath_hw
*ah
= sc
->sc_ah
;
2058 struct ieee80211_vif
*vif
;
2059 struct ath_vif
*avp
;
2061 struct ath_tx_status ts
;
2062 bool edma
= !!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
);
2065 vif
= sc
->beacon
.bslot
[0];
2069 if (!vif
->bss_conf
.enable_beacon
)
2072 avp
= (void *)vif
->drv_priv
;
2074 if (!sc
->beacon
.tx_processed
&& !edma
) {
2075 tasklet_disable(&sc
->bcon_tasklet
);
2078 if (!bf
|| !bf
->bf_mpdu
)
2081 status
= ath9k_hw_txprocdesc(ah
, bf
->bf_desc
, &ts
);
2082 if (status
== -EINPROGRESS
)
2085 sc
->beacon
.tx_processed
= true;
2086 sc
->beacon
.tx_last
= !(ts
.ts_status
& ATH9K_TXERR_MASK
);
2089 tasklet_enable(&sc
->bcon_tasklet
);
2092 return sc
->beacon
.tx_last
;
2095 static int ath9k_get_stats(struct ieee80211_hw
*hw
,
2096 struct ieee80211_low_level_stats
*stats
)
2098 struct ath_softc
*sc
= hw
->priv
;
2099 struct ath_hw
*ah
= sc
->sc_ah
;
2100 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
2102 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
2103 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
2104 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
2105 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
2109 static u32
fill_chainmask(u32 cap
, u32
new)
2114 for (i
= 0; cap
&& new; i
++, cap
>>= 1) {
2115 if (!(cap
& BIT(0)))
2127 static bool validate_antenna_mask(struct ath_hw
*ah
, u32 val
)
2129 if (AR_SREV_9300_20_OR_LATER(ah
))
2132 switch (val
& 0x7) {
2138 return (ah
->caps
.rx_chainmask
== 1);
2144 static int ath9k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
2146 struct ath_softc
*sc
= hw
->priv
;
2147 struct ath_hw
*ah
= sc
->sc_ah
;
2149 if (ah
->caps
.rx_chainmask
!= 1)
2152 if (!validate_antenna_mask(ah
, rx_ant
) || !tx_ant
)
2155 sc
->ant_rx
= rx_ant
;
2156 sc
->ant_tx
= tx_ant
;
2158 if (ah
->caps
.rx_chainmask
== 1)
2161 /* AR9100 runs into calibration issues if not all rx chains are enabled */
2162 if (AR_SREV_9100(ah
))
2163 ah
->rxchainmask
= 0x7;
2165 ah
->rxchainmask
= fill_chainmask(ah
->caps
.rx_chainmask
, rx_ant
);
2167 ah
->txchainmask
= fill_chainmask(ah
->caps
.tx_chainmask
, tx_ant
);
2168 ath9k_cmn_reload_chainmask(ah
);
2173 static int ath9k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
2175 struct ath_softc
*sc
= hw
->priv
;
2177 *tx_ant
= sc
->ant_tx
;
2178 *rx_ant
= sc
->ant_rx
;
2182 static void ath9k_sw_scan_start(struct ieee80211_hw
*hw
)
2184 struct ath_softc
*sc
= hw
->priv
;
2185 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2186 set_bit(ATH_OP_SCANNING
, &common
->op_flags
);
2189 static void ath9k_sw_scan_complete(struct ieee80211_hw
*hw
)
2191 struct ath_softc
*sc
= hw
->priv
;
2192 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2193 clear_bit(ATH_OP_SCANNING
, &common
->op_flags
);
2196 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
2198 static int ath9k_hw_scan(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
2199 struct ieee80211_scan_request
*hw_req
)
2201 struct cfg80211_scan_request
*req
= &hw_req
->req
;
2202 struct ath_softc
*sc
= hw
->priv
;
2203 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2206 mutex_lock(&sc
->mutex
);
2208 if (WARN_ON(sc
->offchannel
.scan_req
)) {
2213 ath9k_ps_wakeup(sc
);
2214 set_bit(ATH_OP_SCANNING
, &common
->op_flags
);
2215 sc
->offchannel
.scan_vif
= vif
;
2216 sc
->offchannel
.scan_req
= req
;
2217 sc
->offchannel
.scan_idx
= 0;
2219 ath_dbg(common
, CHAN_CTX
, "HW scan request received on vif: %pM\n",
2222 if (sc
->offchannel
.state
== ATH_OFFCHANNEL_IDLE
) {
2223 ath_dbg(common
, CHAN_CTX
, "Starting HW scan\n");
2224 ath_offchannel_next(sc
);
2228 mutex_unlock(&sc
->mutex
);
2233 static void ath9k_cancel_hw_scan(struct ieee80211_hw
*hw
,
2234 struct ieee80211_vif
*vif
)
2236 struct ath_softc
*sc
= hw
->priv
;
2237 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2239 ath_dbg(common
, CHAN_CTX
, "Cancel HW scan on vif: %pM\n", vif
->addr
);
2241 mutex_lock(&sc
->mutex
);
2242 del_timer_sync(&sc
->offchannel
.timer
);
2243 ath_scan_complete(sc
, true);
2244 mutex_unlock(&sc
->mutex
);
2247 static int ath9k_remain_on_channel(struct ieee80211_hw
*hw
,
2248 struct ieee80211_vif
*vif
,
2249 struct ieee80211_channel
*chan
, int duration
,
2250 enum ieee80211_roc_type type
)
2252 struct ath_softc
*sc
= hw
->priv
;
2253 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2256 mutex_lock(&sc
->mutex
);
2258 if (WARN_ON(sc
->offchannel
.roc_vif
)) {
2263 ath9k_ps_wakeup(sc
);
2264 sc
->offchannel
.roc_vif
= vif
;
2265 sc
->offchannel
.roc_chan
= chan
;
2266 sc
->offchannel
.roc_duration
= duration
;
2268 ath_dbg(common
, CHAN_CTX
,
2269 "RoC request on vif: %pM, type: %d duration: %d\n",
2270 vif
->addr
, type
, duration
);
2272 if (sc
->offchannel
.state
== ATH_OFFCHANNEL_IDLE
) {
2273 ath_dbg(common
, CHAN_CTX
, "Starting RoC period\n");
2274 ath_offchannel_next(sc
);
2278 mutex_unlock(&sc
->mutex
);
2283 static int ath9k_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
2285 struct ath_softc
*sc
= hw
->priv
;
2286 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2288 mutex_lock(&sc
->mutex
);
2290 ath_dbg(common
, CHAN_CTX
, "Cancel RoC\n");
2291 del_timer_sync(&sc
->offchannel
.timer
);
2293 if (sc
->offchannel
.roc_vif
) {
2294 if (sc
->offchannel
.state
>= ATH_OFFCHANNEL_ROC_START
)
2295 ath_roc_complete(sc
, true);
2298 mutex_unlock(&sc
->mutex
);
2303 static int ath9k_add_chanctx(struct ieee80211_hw
*hw
,
2304 struct ieee80211_chanctx_conf
*conf
)
2306 struct ath_softc
*sc
= hw
->priv
;
2307 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2308 struct ath_chanctx
*ctx
, **ptr
;
2311 mutex_lock(&sc
->mutex
);
2313 ath_for_each_chanctx(sc
, ctx
) {
2317 ptr
= (void *) conf
->drv_priv
;
2319 ctx
->assigned
= true;
2320 pos
= ctx
- &sc
->chanctx
[0];
2321 ctx
->hw_queue_base
= pos
* IEEE80211_NUM_ACS
;
2323 ath_dbg(common
, CHAN_CTX
,
2324 "Add channel context: %d MHz\n",
2325 conf
->def
.chan
->center_freq
);
2327 ath_chanctx_set_channel(sc
, ctx
, &conf
->def
);
2328 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_ASSIGN
);
2330 mutex_unlock(&sc
->mutex
);
2334 mutex_unlock(&sc
->mutex
);
2339 static void ath9k_remove_chanctx(struct ieee80211_hw
*hw
,
2340 struct ieee80211_chanctx_conf
*conf
)
2342 struct ath_softc
*sc
= hw
->priv
;
2343 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2344 struct ath_chanctx
*ctx
= ath_chanctx_get(conf
);
2346 mutex_lock(&sc
->mutex
);
2348 ath_dbg(common
, CHAN_CTX
,
2349 "Remove channel context: %d MHz\n",
2350 conf
->def
.chan
->center_freq
);
2352 ctx
->assigned
= false;
2353 ctx
->hw_queue_base
= -1;
2354 ath_chanctx_event(sc
, NULL
, ATH_CHANCTX_EVENT_UNASSIGN
);
2356 mutex_unlock(&sc
->mutex
);
2359 static void ath9k_change_chanctx(struct ieee80211_hw
*hw
,
2360 struct ieee80211_chanctx_conf
*conf
,
2363 struct ath_softc
*sc
= hw
->priv
;
2364 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2365 struct ath_chanctx
*ctx
= ath_chanctx_get(conf
);
2367 mutex_lock(&sc
->mutex
);
2368 ath_dbg(common
, CHAN_CTX
,
2369 "Change channel context: %d MHz\n",
2370 conf
->def
.chan
->center_freq
);
2371 ath_chanctx_set_channel(sc
, ctx
, &conf
->def
);
2372 mutex_unlock(&sc
->mutex
);
2375 static int ath9k_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2376 struct ieee80211_vif
*vif
,
2377 struct ieee80211_chanctx_conf
*conf
)
2379 struct ath_softc
*sc
= hw
->priv
;
2380 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2381 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
2382 struct ath_chanctx
*ctx
= ath_chanctx_get(conf
);
2385 mutex_lock(&sc
->mutex
);
2387 ath_dbg(common
, CHAN_CTX
,
2388 "Assign VIF (addr: %pM, type: %d, p2p: %d) to channel context: %d MHz\n",
2389 vif
->addr
, vif
->type
, vif
->p2p
,
2390 conf
->def
.chan
->center_freq
);
2393 ctx
->nvifs_assigned
++;
2394 list_add_tail(&avp
->list
, &ctx
->vifs
);
2395 ath9k_calculate_summary_state(sc
, ctx
);
2396 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
2397 vif
->hw_queue
[i
] = ctx
->hw_queue_base
+ i
;
2399 mutex_unlock(&sc
->mutex
);
2404 static void ath9k_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2405 struct ieee80211_vif
*vif
,
2406 struct ieee80211_chanctx_conf
*conf
)
2408 struct ath_softc
*sc
= hw
->priv
;
2409 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2410 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
2411 struct ath_chanctx
*ctx
= ath_chanctx_get(conf
);
2414 mutex_lock(&sc
->mutex
);
2416 ath_dbg(common
, CHAN_CTX
,
2417 "Remove VIF (addr: %pM, type: %d, p2p: %d) from channel context: %d MHz\n",
2418 vif
->addr
, vif
->type
, vif
->p2p
,
2419 conf
->def
.chan
->center_freq
);
2421 avp
->chanctx
= NULL
;
2422 ctx
->nvifs_assigned
--;
2423 list_del(&avp
->list
);
2424 ath9k_calculate_summary_state(sc
, ctx
);
2425 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
2426 vif
->hw_queue
[ac
] = IEEE80211_INVAL_HW_QUEUE
;
2428 mutex_unlock(&sc
->mutex
);
2431 static void ath9k_mgd_prepare_tx(struct ieee80211_hw
*hw
,
2432 struct ieee80211_vif
*vif
)
2434 struct ath_softc
*sc
= hw
->priv
;
2435 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
2436 struct ath_vif
*avp
= (struct ath_vif
*) vif
->drv_priv
;
2437 bool changed
= false;
2439 if (!test_bit(ATH_OP_MULTI_CHANNEL
, &common
->op_flags
))
2445 mutex_lock(&sc
->mutex
);
2447 spin_lock_bh(&sc
->chan_lock
);
2448 if (sc
->next_chan
|| (sc
->cur_chan
!= avp
->chanctx
)) {
2449 sc
->next_chan
= avp
->chanctx
;
2452 ath_dbg(common
, CHAN_CTX
,
2453 "%s: Set chanctx state to FORCE_ACTIVE, changed: %d\n",
2455 sc
->sched
.state
= ATH_CHANCTX_STATE_FORCE_ACTIVE
;
2456 spin_unlock_bh(&sc
->chan_lock
);
2459 ath_chanctx_set_next(sc
, true);
2461 mutex_unlock(&sc
->mutex
);
2464 void ath9k_fill_chanctx_ops(void)
2466 if (!ath9k_is_chanctx_enabled())
2469 ath9k_ops
.hw_scan
= ath9k_hw_scan
;
2470 ath9k_ops
.cancel_hw_scan
= ath9k_cancel_hw_scan
;
2471 ath9k_ops
.remain_on_channel
= ath9k_remain_on_channel
;
2472 ath9k_ops
.cancel_remain_on_channel
= ath9k_cancel_remain_on_channel
;
2473 ath9k_ops
.add_chanctx
= ath9k_add_chanctx
;
2474 ath9k_ops
.remove_chanctx
= ath9k_remove_chanctx
;
2475 ath9k_ops
.change_chanctx
= ath9k_change_chanctx
;
2476 ath9k_ops
.assign_vif_chanctx
= ath9k_assign_vif_chanctx
;
2477 ath9k_ops
.unassign_vif_chanctx
= ath9k_unassign_vif_chanctx
;
2478 ath9k_ops
.mgd_prepare_tx
= ath9k_mgd_prepare_tx
;
2483 struct ieee80211_ops ath9k_ops
= {
2485 .start
= ath9k_start
,
2487 .add_interface
= ath9k_add_interface
,
2488 .change_interface
= ath9k_change_interface
,
2489 .remove_interface
= ath9k_remove_interface
,
2490 .config
= ath9k_config
,
2491 .configure_filter
= ath9k_configure_filter
,
2492 .sta_add
= ath9k_sta_add
,
2493 .sta_remove
= ath9k_sta_remove
,
2494 .sta_notify
= ath9k_sta_notify
,
2495 .conf_tx
= ath9k_conf_tx
,
2496 .bss_info_changed
= ath9k_bss_info_changed
,
2497 .set_key
= ath9k_set_key
,
2498 .get_tsf
= ath9k_get_tsf
,
2499 .set_tsf
= ath9k_set_tsf
,
2500 .reset_tsf
= ath9k_reset_tsf
,
2501 .ampdu_action
= ath9k_ampdu_action
,
2502 .get_survey
= ath9k_get_survey
,
2503 .rfkill_poll
= ath9k_rfkill_poll_state
,
2504 .set_coverage_class
= ath9k_set_coverage_class
,
2505 .flush
= ath9k_flush
,
2506 .tx_frames_pending
= ath9k_tx_frames_pending
,
2507 .tx_last_beacon
= ath9k_tx_last_beacon
,
2508 .release_buffered_frames
= ath9k_release_buffered_frames
,
2509 .get_stats
= ath9k_get_stats
,
2510 .set_antenna
= ath9k_set_antenna
,
2511 .get_antenna
= ath9k_get_antenna
,
2513 #ifdef CONFIG_ATH9K_WOW
2514 .suspend
= ath9k_suspend
,
2515 .resume
= ath9k_resume
,
2516 .set_wakeup
= ath9k_set_wakeup
,
2519 #ifdef CONFIG_ATH9K_DEBUGFS
2520 .get_et_sset_count
= ath9k_get_et_sset_count
,
2521 .get_et_stats
= ath9k_get_et_stats
,
2522 .get_et_strings
= ath9k_get_et_strings
,
2525 #if defined(CONFIG_MAC80211_DEBUGFS) && defined(CONFIG_ATH9K_STATION_STATISTICS)
2526 .sta_add_debugfs
= ath9k_sta_add_debugfs
,
2528 .sw_scan_start
= ath9k_sw_scan_start
,
2529 .sw_scan_complete
= ath9k_sw_scan_complete
,