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 static void ath9k_set_assoc_state(struct ath_softc
*sc
,
23 struct ieee80211_vif
*vif
);
25 u8
ath9k_parse_mpdudensity(u8 mpdudensity
)
28 * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
29 * 0 for no restriction
38 switch (mpdudensity
) {
44 /* Our lower layer calculations limit our precision to
60 static bool ath9k_has_pending_frames(struct ath_softc
*sc
, struct ath_txq
*txq
)
64 spin_lock_bh(&txq
->axq_lock
);
66 if (txq
->axq_depth
|| !list_empty(&txq
->axq_acq
))
69 spin_unlock_bh(&txq
->axq_lock
);
73 static bool ath9k_setpower(struct ath_softc
*sc
, enum ath9k_power_mode mode
)
78 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
79 ret
= ath9k_hw_setpower(sc
->sc_ah
, mode
);
80 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
85 void ath9k_ps_wakeup(struct ath_softc
*sc
)
87 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
89 enum ath9k_power_mode power_mode
;
91 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
92 if (++sc
->ps_usecount
!= 1)
95 power_mode
= sc
->sc_ah
->power_mode
;
96 ath9k_hw_setpower(sc
->sc_ah
, ATH9K_PM_AWAKE
);
99 * While the hardware is asleep, the cycle counters contain no
100 * useful data. Better clear them now so that they don't mess up
101 * survey data results.
103 if (power_mode
!= ATH9K_PM_AWAKE
) {
104 spin_lock(&common
->cc_lock
);
105 ath_hw_cycle_counters_update(common
);
106 memset(&common
->cc_survey
, 0, sizeof(common
->cc_survey
));
107 memset(&common
->cc_ani
, 0, sizeof(common
->cc_ani
));
108 spin_unlock(&common
->cc_lock
);
112 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
115 void ath9k_ps_restore(struct ath_softc
*sc
)
117 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
118 enum ath9k_power_mode mode
;
122 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
123 if (--sc
->ps_usecount
!= 0)
127 ath9k_hw_setrxabort(sc
->sc_ah
, 1);
128 ath9k_hw_stopdmarecv(sc
->sc_ah
, &reset
);
129 mode
= ATH9K_PM_FULL_SLEEP
;
130 } else if (sc
->ps_enabled
&&
131 !(sc
->ps_flags
& (PS_WAIT_FOR_BEACON
|
133 PS_WAIT_FOR_PSPOLL_DATA
|
136 mode
= ATH9K_PM_NETWORK_SLEEP
;
137 if (ath9k_hw_btcoex_is_enabled(sc
->sc_ah
))
138 ath9k_btcoex_stop_gen_timer(sc
);
143 spin_lock(&common
->cc_lock
);
144 ath_hw_cycle_counters_update(common
);
145 spin_unlock(&common
->cc_lock
);
147 ath9k_hw_setpower(sc
->sc_ah
, mode
);
150 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
153 static void __ath_cancel_work(struct ath_softc
*sc
)
155 cancel_work_sync(&sc
->paprd_work
);
156 cancel_work_sync(&sc
->hw_check_work
);
157 cancel_delayed_work_sync(&sc
->tx_complete_work
);
158 cancel_delayed_work_sync(&sc
->hw_pll_work
);
160 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
161 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
))
162 cancel_work_sync(&sc
->mci_work
);
166 static void ath_cancel_work(struct ath_softc
*sc
)
168 __ath_cancel_work(sc
);
169 cancel_work_sync(&sc
->hw_reset_work
);
172 static void ath_restart_work(struct ath_softc
*sc
)
174 ieee80211_queue_delayed_work(sc
->hw
, &sc
->tx_complete_work
, 0);
176 if (AR_SREV_9340(sc
->sc_ah
) || AR_SREV_9485(sc
->sc_ah
) ||
177 AR_SREV_9550(sc
->sc_ah
))
178 ieee80211_queue_delayed_work(sc
->hw
, &sc
->hw_pll_work
,
179 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL
));
181 ath_start_rx_poll(sc
, 3);
185 static bool ath_prepare_reset(struct ath_softc
*sc
, bool retry_tx
, bool flush
)
187 struct ath_hw
*ah
= sc
->sc_ah
;
190 ieee80211_stop_queues(sc
->hw
);
192 sc
->hw_busy_count
= 0;
194 del_timer_sync(&sc
->rx_poll_timer
);
196 ath9k_debug_samp_bb_mac(sc
);
197 ath9k_hw_disable_interrupts(ah
);
199 if (!ath_stoprecv(sc
))
202 if (!ath_drain_all_txq(sc
, retry_tx
))
206 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
207 ath_rx_tasklet(sc
, 1, true);
208 ath_rx_tasklet(sc
, 1, false);
216 static bool ath_complete_reset(struct ath_softc
*sc
, bool start
)
218 struct ath_hw
*ah
= sc
->sc_ah
;
219 struct ath_common
*common
= ath9k_hw_common(ah
);
222 if (ath_startrecv(sc
) != 0) {
223 ath_err(common
, "Unable to restart recv logic\n");
227 ath9k_cmn_update_txpow(ah
, sc
->curtxpow
,
228 sc
->config
.txpowlimit
, &sc
->curtxpow
);
230 clear_bit(SC_OP_HW_RESET
, &sc
->sc_flags
);
231 ath9k_hw_set_interrupts(ah
);
232 ath9k_hw_enable_interrupts(ah
);
234 if (!(sc
->hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
) && start
) {
235 if (!test_bit(SC_OP_BEACONS
, &sc
->sc_flags
))
238 ath9k_set_beacon(sc
);
240 if (ah
->opmode
== NL80211_IFTYPE_STATION
&&
241 test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
)) {
242 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
243 sc
->ps_flags
|= PS_BEACON_SYNC
| PS_WAIT_FOR_BEACON
;
244 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
247 ath_restart_work(sc
);
250 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_ANT_DIV_COMB
) && sc
->ant_rx
!= 3)
251 ath_ant_comb_update(sc
);
253 ieee80211_wake_queues(sc
->hw
);
258 static int ath_reset_internal(struct ath_softc
*sc
, struct ath9k_channel
*hchan
,
261 struct ath_hw
*ah
= sc
->sc_ah
;
262 struct ath_common
*common
= ath9k_hw_common(ah
);
263 struct ath9k_hw_cal_data
*caldata
= NULL
;
268 __ath_cancel_work(sc
);
270 spin_lock_bh(&sc
->sc_pcu_lock
);
272 if (!(sc
->hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
)) {
274 caldata
= &sc
->caldata
;
283 if (!ath_prepare_reset(sc
, retry_tx
, flush
))
286 ath_dbg(common
, CONFIG
, "Reset to %u MHz, HT40: %d fastcc: %d\n",
287 hchan
->channel
, IS_CHAN_HT40(hchan
), fastcc
);
289 r
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
292 "Unable to reset channel, reset status %d\n", r
);
296 if (!ath_complete_reset(sc
, true))
300 spin_unlock_bh(&sc
->sc_pcu_lock
);
306 * Set/change channels. If the channel is really being changed, it's done
307 * by reseting the chip. To accomplish this we must first cleanup any pending
308 * DMA, then restart stuff.
310 static int ath_set_channel(struct ath_softc
*sc
, struct ieee80211_hw
*hw
,
311 struct ath9k_channel
*hchan
)
315 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
))
318 r
= ath_reset_internal(sc
, hchan
, false);
323 static void ath_node_attach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
,
324 struct ieee80211_vif
*vif
)
328 an
= (struct ath_node
*)sta
->drv_priv
;
330 #ifdef CONFIG_ATH9K_DEBUGFS
331 spin_lock(&sc
->nodes_lock
);
332 list_add(&an
->list
, &sc
->nodes
);
333 spin_unlock(&sc
->nodes_lock
);
338 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
) {
339 ath_tx_node_init(sc
, an
);
340 an
->maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
341 sta
->ht_cap
.ampdu_factor
);
342 density
= ath9k_parse_mpdudensity(sta
->ht_cap
.ampdu_density
);
343 an
->mpdudensity
= density
;
347 static void ath_node_detach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
)
349 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
351 #ifdef CONFIG_ATH9K_DEBUGFS
352 spin_lock(&sc
->nodes_lock
);
354 spin_unlock(&sc
->nodes_lock
);
358 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
359 ath_tx_node_cleanup(sc
, an
);
362 void ath9k_tasklet(unsigned long data
)
364 struct ath_softc
*sc
= (struct ath_softc
*)data
;
365 struct ath_hw
*ah
= sc
->sc_ah
;
366 struct ath_common
*common
= ath9k_hw_common(ah
);
367 enum ath_reset_type type
;
369 u32 status
= sc
->intrstatus
;
373 spin_lock(&sc
->sc_pcu_lock
);
375 if ((status
& ATH9K_INT_FATAL
) ||
376 (status
& ATH9K_INT_BB_WATCHDOG
)) {
378 if (status
& ATH9K_INT_FATAL
)
379 type
= RESET_TYPE_FATAL_INT
;
381 type
= RESET_TYPE_BB_WATCHDOG
;
383 ath9k_queue_reset(sc
, type
);
387 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
388 if ((status
& ATH9K_INT_TSFOOR
) && sc
->ps_enabled
) {
390 * TSF sync does not look correct; remain awake to sync with
393 ath_dbg(common
, PS
, "TSFOOR - Sync with next Beacon\n");
394 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
| PS_BEACON_SYNC
;
396 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
398 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
399 rxmask
= (ATH9K_INT_RXHP
| ATH9K_INT_RXLP
| ATH9K_INT_RXEOL
|
402 rxmask
= (ATH9K_INT_RX
| ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
404 if (status
& rxmask
) {
405 /* Check for high priority Rx first */
406 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) &&
407 (status
& ATH9K_INT_RXHP
))
408 ath_rx_tasklet(sc
, 0, true);
410 ath_rx_tasklet(sc
, 0, false);
413 if (status
& ATH9K_INT_TX
) {
414 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
415 ath_tx_edma_tasklet(sc
);
420 ath9k_btcoex_handle_interrupt(sc
, status
);
423 /* re-enable hardware interrupt */
424 ath9k_hw_enable_interrupts(ah
);
426 spin_unlock(&sc
->sc_pcu_lock
);
427 ath9k_ps_restore(sc
);
430 irqreturn_t
ath_isr(int irq
, void *dev
)
432 #define SCHED_INTR ( \
434 ATH9K_INT_BB_WATCHDOG | \
444 ATH9K_INT_GENTIMER | \
447 struct ath_softc
*sc
= dev
;
448 struct ath_hw
*ah
= sc
->sc_ah
;
449 struct ath_common
*common
= ath9k_hw_common(ah
);
450 enum ath9k_int status
;
454 * The hardware is not ready/present, don't
455 * touch anything. Note this can happen early
456 * on if the IRQ is shared.
458 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
))
461 /* shared irq, not for us */
463 if (!ath9k_hw_intrpend(ah
))
466 if (test_bit(SC_OP_HW_RESET
, &sc
->sc_flags
)) {
467 ath9k_hw_kill_interrupts(ah
);
472 * Figure out the reason(s) for the interrupt. Note
473 * that the hal returns a pseudo-ISR that may include
474 * bits we haven't explicitly enabled so we mask the
475 * value to insure we only process bits we requested.
477 ath9k_hw_getisr(ah
, &status
); /* NB: clears ISR too */
478 status
&= ah
->imask
; /* discard unasked-for bits */
481 * If there are no status bits set, then this interrupt was not
482 * for me (should have been caught above).
487 /* Cache the status */
488 sc
->intrstatus
= status
;
490 if (status
& SCHED_INTR
)
493 #ifdef CONFIG_PM_SLEEP
494 if (status
& ATH9K_INT_BMISS
) {
495 if (atomic_read(&sc
->wow_sleep_proc_intr
) == 0) {
496 ath_dbg(common
, ANY
, "during WoW we got a BMISS\n");
497 atomic_inc(&sc
->wow_got_bmiss_intr
);
498 atomic_dec(&sc
->wow_sleep_proc_intr
);
500 ath_dbg(common
, INTERRUPT
, "beacon miss interrupt\n");
505 * If a FATAL or RXORN interrupt is received, we have to reset the
508 if ((status
& ATH9K_INT_FATAL
) || ((status
& ATH9K_INT_RXORN
) &&
509 !(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)))
512 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) &&
513 (status
& ATH9K_INT_BB_WATCHDOG
)) {
515 spin_lock(&common
->cc_lock
);
516 ath_hw_cycle_counters_update(common
);
517 ar9003_hw_bb_watchdog_dbg_info(ah
);
518 spin_unlock(&common
->cc_lock
);
523 if (status
& ATH9K_INT_SWBA
)
524 tasklet_schedule(&sc
->bcon_tasklet
);
526 if (status
& ATH9K_INT_TXURN
)
527 ath9k_hw_updatetxtriglevel(ah
, true);
529 if (status
& ATH9K_INT_RXEOL
) {
530 ah
->imask
&= ~(ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
531 ath9k_hw_set_interrupts(ah
);
534 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
535 if (status
& ATH9K_INT_TIM_TIMER
) {
536 if (ATH_DBG_WARN_ON_ONCE(sc
->ps_idle
))
538 /* Clear RxAbort bit so that we can
540 ath9k_setpower(sc
, ATH9K_PM_AWAKE
);
541 spin_lock(&sc
->sc_pm_lock
);
542 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
543 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
;
544 spin_unlock(&sc
->sc_pm_lock
);
549 ath_debug_stat_interrupt(sc
, status
);
552 /* turn off every interrupt */
553 ath9k_hw_disable_interrupts(ah
);
554 tasklet_schedule(&sc
->intr_tq
);
562 static int ath_reset(struct ath_softc
*sc
, bool retry_tx
)
568 r
= ath_reset_internal(sc
, NULL
, retry_tx
);
572 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
573 if (ATH_TXQ_SETUP(sc
, i
)) {
574 spin_lock_bh(&sc
->tx
.txq
[i
].axq_lock
);
575 ath_txq_schedule(sc
, &sc
->tx
.txq
[i
]);
576 spin_unlock_bh(&sc
->tx
.txq
[i
].axq_lock
);
581 ath9k_ps_restore(sc
);
586 void ath9k_queue_reset(struct ath_softc
*sc
, enum ath_reset_type type
)
588 #ifdef CONFIG_ATH9K_DEBUGFS
589 RESET_STAT_INC(sc
, type
);
591 set_bit(SC_OP_HW_RESET
, &sc
->sc_flags
);
592 ieee80211_queue_work(sc
->hw
, &sc
->hw_reset_work
);
595 void ath_reset_work(struct work_struct
*work
)
597 struct ath_softc
*sc
= container_of(work
, struct ath_softc
, hw_reset_work
);
602 /**********************/
603 /* mac80211 callbacks */
604 /**********************/
606 static int ath9k_start(struct ieee80211_hw
*hw
)
608 struct ath_softc
*sc
= hw
->priv
;
609 struct ath_hw
*ah
= sc
->sc_ah
;
610 struct ath_common
*common
= ath9k_hw_common(ah
);
611 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
612 struct ath9k_channel
*init_channel
;
615 ath_dbg(common
, CONFIG
,
616 "Starting driver with initial channel: %d MHz\n",
617 curchan
->center_freq
);
620 mutex_lock(&sc
->mutex
);
622 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
624 /* Reset SERDES registers */
625 ath9k_hw_configpcipowersave(ah
, false);
628 * The basic interface to setting the hardware in a good
629 * state is ``reset''. On return the hardware is known to
630 * be powered up and with interrupts disabled. This must
631 * be followed by initialization of the appropriate bits
632 * and then setup of the interrupt mask.
634 spin_lock_bh(&sc
->sc_pcu_lock
);
636 atomic_set(&ah
->intr_ref_cnt
, -1);
638 r
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
641 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
642 r
, curchan
->center_freq
);
643 ah
->reset_power_on
= false;
646 /* Setup our intr mask. */
647 ah
->imask
= ATH9K_INT_TX
| ATH9K_INT_RXEOL
|
648 ATH9K_INT_RXORN
| ATH9K_INT_FATAL
|
651 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
652 ah
->imask
|= ATH9K_INT_RXHP
|
654 ATH9K_INT_BB_WATCHDOG
;
656 ah
->imask
|= ATH9K_INT_RX
;
658 ah
->imask
|= ATH9K_INT_GTT
;
660 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
661 ah
->imask
|= ATH9K_INT_CST
;
665 clear_bit(SC_OP_INVALID
, &sc
->sc_flags
);
666 sc
->sc_ah
->is_monitoring
= false;
668 if (!ath_complete_reset(sc
, false))
669 ah
->reset_power_on
= false;
671 if (ah
->led_pin
>= 0) {
672 ath9k_hw_cfg_output(ah
, ah
->led_pin
,
673 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
674 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 0);
678 * Reset key cache to sane defaults (all entries cleared) instead of
679 * semi-random values after suspend/resume.
681 ath9k_cmn_init_crypto(sc
->sc_ah
);
683 spin_unlock_bh(&sc
->sc_pcu_lock
);
685 if (ah
->caps
.pcie_lcr_extsync_en
&& common
->bus_ops
->extn_synch_en
)
686 common
->bus_ops
->extn_synch_en(common
);
688 mutex_unlock(&sc
->mutex
);
690 ath9k_ps_restore(sc
);
695 static void ath9k_tx(struct ieee80211_hw
*hw
,
696 struct ieee80211_tx_control
*control
,
699 struct ath_softc
*sc
= hw
->priv
;
700 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
701 struct ath_tx_control txctl
;
702 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
705 if (sc
->ps_enabled
) {
707 * mac80211 does not set PM field for normal data frames, so we
708 * need to update that based on the current PS mode.
710 if (ieee80211_is_data(hdr
->frame_control
) &&
711 !ieee80211_is_nullfunc(hdr
->frame_control
) &&
712 !ieee80211_has_pm(hdr
->frame_control
)) {
714 "Add PM=1 for a TX frame while in PS mode\n");
715 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
719 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_NETWORK_SLEEP
)) {
721 * We are using PS-Poll and mac80211 can request TX while in
722 * power save mode. Need to wake up hardware for the TX to be
723 * completed and if needed, also for RX of buffered frames.
726 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
727 if (!(sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
728 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
729 if (ieee80211_is_pspoll(hdr
->frame_control
)) {
731 "Sending PS-Poll to pick a buffered frame\n");
732 sc
->ps_flags
|= PS_WAIT_FOR_PSPOLL_DATA
;
734 ath_dbg(common
, PS
, "Wake up to complete TX\n");
735 sc
->ps_flags
|= PS_WAIT_FOR_TX_ACK
;
738 * The actual restore operation will happen only after
739 * the ps_flags bit is cleared. We are just dropping
740 * the ps_usecount here.
742 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
743 ath9k_ps_restore(sc
);
747 * Cannot tx while the hardware is in full sleep, it first needs a full
748 * chip reset to recover from that
750 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_FULL_SLEEP
)) {
751 ath_err(common
, "TX while HW is in FULL_SLEEP mode\n");
755 memset(&txctl
, 0, sizeof(struct ath_tx_control
));
756 txctl
.txq
= sc
->tx
.txq_map
[skb_get_queue_mapping(skb
)];
757 txctl
.sta
= control
->sta
;
759 ath_dbg(common
, XMIT
, "transmitting packet, skb: %p\n", skb
);
761 if (ath_tx_start(hw
, skb
, &txctl
) != 0) {
762 ath_dbg(common
, XMIT
, "TX failed\n");
763 TX_STAT_INC(txctl
.txq
->axq_qnum
, txfailed
);
769 ieee80211_free_txskb(hw
, skb
);
772 static void ath9k_stop(struct ieee80211_hw
*hw
)
774 struct ath_softc
*sc
= hw
->priv
;
775 struct ath_hw
*ah
= sc
->sc_ah
;
776 struct ath_common
*common
= ath9k_hw_common(ah
);
779 mutex_lock(&sc
->mutex
);
782 del_timer_sync(&sc
->rx_poll_timer
);
784 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
785 ath_dbg(common
, ANY
, "Device not present\n");
786 mutex_unlock(&sc
->mutex
);
790 /* Ensure HW is awake when we try to shut it down. */
793 spin_lock_bh(&sc
->sc_pcu_lock
);
795 /* prevent tasklets to enable interrupts once we disable them */
796 ah
->imask
&= ~ATH9K_INT_GLOBAL
;
798 /* make sure h/w will not generate any interrupt
799 * before setting the invalid flag. */
800 ath9k_hw_disable_interrupts(ah
);
802 spin_unlock_bh(&sc
->sc_pcu_lock
);
804 /* we can now sync irq and kill any running tasklets, since we already
805 * disabled interrupts and not holding a spin lock */
806 synchronize_irq(sc
->irq
);
807 tasklet_kill(&sc
->intr_tq
);
808 tasklet_kill(&sc
->bcon_tasklet
);
810 prev_idle
= sc
->ps_idle
;
813 spin_lock_bh(&sc
->sc_pcu_lock
);
815 if (ah
->led_pin
>= 0) {
816 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 1);
817 ath9k_hw_cfg_gpio_input(ah
, ah
->led_pin
);
820 ath_prepare_reset(sc
, false, true);
823 dev_kfree_skb_any(sc
->rx
.frag
);
828 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
830 ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
831 ath9k_hw_phy_disable(ah
);
833 ath9k_hw_configpcipowersave(ah
, true);
835 spin_unlock_bh(&sc
->sc_pcu_lock
);
837 ath9k_ps_restore(sc
);
839 set_bit(SC_OP_INVALID
, &sc
->sc_flags
);
840 sc
->ps_idle
= prev_idle
;
842 mutex_unlock(&sc
->mutex
);
844 ath_dbg(common
, CONFIG
, "Driver halt\n");
847 bool ath9k_uses_beacons(int type
)
850 case NL80211_IFTYPE_AP
:
851 case NL80211_IFTYPE_ADHOC
:
852 case NL80211_IFTYPE_MESH_POINT
:
859 static void ath9k_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
861 struct ath9k_vif_iter_data
*iter_data
= data
;
864 if (iter_data
->hw_macaddr
)
865 for (i
= 0; i
< ETH_ALEN
; i
++)
866 iter_data
->mask
[i
] &=
867 ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
870 case NL80211_IFTYPE_AP
:
873 case NL80211_IFTYPE_STATION
:
874 iter_data
->nstations
++;
876 case NL80211_IFTYPE_ADHOC
:
877 iter_data
->nadhocs
++;
879 case NL80211_IFTYPE_MESH_POINT
:
880 iter_data
->nmeshes
++;
882 case NL80211_IFTYPE_WDS
:
890 static void ath9k_sta_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
892 struct ath_softc
*sc
= data
;
893 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
895 if (vif
->type
!= NL80211_IFTYPE_STATION
)
898 if (avp
->primary_sta_vif
)
899 ath9k_set_assoc_state(sc
, vif
);
902 /* Called with sc->mutex held. */
903 void ath9k_calculate_iter_data(struct ieee80211_hw
*hw
,
904 struct ieee80211_vif
*vif
,
905 struct ath9k_vif_iter_data
*iter_data
)
907 struct ath_softc
*sc
= hw
->priv
;
908 struct ath_hw
*ah
= sc
->sc_ah
;
909 struct ath_common
*common
= ath9k_hw_common(ah
);
912 * Use the hardware MAC address as reference, the hardware uses it
913 * together with the BSSID mask when matching addresses.
915 memset(iter_data
, 0, sizeof(*iter_data
));
916 iter_data
->hw_macaddr
= common
->macaddr
;
917 memset(&iter_data
->mask
, 0xff, ETH_ALEN
);
920 ath9k_vif_iter(iter_data
, vif
->addr
, vif
);
922 /* Get list of all active MAC addresses */
923 ieee80211_iterate_active_interfaces_atomic(sc
->hw
, ath9k_vif_iter
,
927 /* Called with sc->mutex held. */
928 static void ath9k_calculate_summary_state(struct ieee80211_hw
*hw
,
929 struct ieee80211_vif
*vif
)
931 struct ath_softc
*sc
= hw
->priv
;
932 struct ath_hw
*ah
= sc
->sc_ah
;
933 struct ath_common
*common
= ath9k_hw_common(ah
);
934 struct ath9k_vif_iter_data iter_data
;
935 enum nl80211_iftype old_opmode
= ah
->opmode
;
937 ath9k_calculate_iter_data(hw
, vif
, &iter_data
);
939 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
940 ath_hw_setbssidmask(common
);
942 if (iter_data
.naps
> 0) {
943 ath9k_hw_set_tsfadjust(ah
, true);
944 ah
->opmode
= NL80211_IFTYPE_AP
;
946 ath9k_hw_set_tsfadjust(ah
, false);
948 if (iter_data
.nmeshes
)
949 ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
950 else if (iter_data
.nwds
)
951 ah
->opmode
= NL80211_IFTYPE_AP
;
952 else if (iter_data
.nadhocs
)
953 ah
->opmode
= NL80211_IFTYPE_ADHOC
;
955 ah
->opmode
= NL80211_IFTYPE_STATION
;
958 ath9k_hw_setopmode(ah
);
960 if ((iter_data
.nstations
+ iter_data
.nadhocs
+ iter_data
.nmeshes
) > 0)
961 ah
->imask
|= ATH9K_INT_TSFOOR
;
963 ah
->imask
&= ~ATH9K_INT_TSFOOR
;
965 ath9k_hw_set_interrupts(ah
);
968 * If we are changing the opmode to STATION,
969 * a beacon sync needs to be done.
971 if (ah
->opmode
== NL80211_IFTYPE_STATION
&&
972 old_opmode
== NL80211_IFTYPE_AP
&&
973 test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
)) {
974 ieee80211_iterate_active_interfaces_atomic(sc
->hw
,
975 ath9k_sta_vif_iter
, sc
);
979 static int ath9k_add_interface(struct ieee80211_hw
*hw
,
980 struct ieee80211_vif
*vif
)
982 struct ath_softc
*sc
= hw
->priv
;
983 struct ath_hw
*ah
= sc
->sc_ah
;
984 struct ath_common
*common
= ath9k_hw_common(ah
);
986 mutex_lock(&sc
->mutex
);
988 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d\n", vif
->type
);
992 ath9k_calculate_summary_state(hw
, vif
);
993 ath9k_ps_restore(sc
);
995 if (ath9k_uses_beacons(vif
->type
))
996 ath9k_beacon_assign_slot(sc
, vif
);
998 mutex_unlock(&sc
->mutex
);
1002 static int ath9k_change_interface(struct ieee80211_hw
*hw
,
1003 struct ieee80211_vif
*vif
,
1004 enum nl80211_iftype new_type
,
1007 struct ath_softc
*sc
= hw
->priv
;
1008 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1010 ath_dbg(common
, CONFIG
, "Change Interface\n");
1011 mutex_lock(&sc
->mutex
);
1013 if (ath9k_uses_beacons(vif
->type
))
1014 ath9k_beacon_remove_slot(sc
, vif
);
1016 vif
->type
= new_type
;
1019 ath9k_ps_wakeup(sc
);
1020 ath9k_calculate_summary_state(hw
, vif
);
1021 ath9k_ps_restore(sc
);
1023 if (ath9k_uses_beacons(vif
->type
))
1024 ath9k_beacon_assign_slot(sc
, vif
);
1026 mutex_unlock(&sc
->mutex
);
1030 static void ath9k_remove_interface(struct ieee80211_hw
*hw
,
1031 struct ieee80211_vif
*vif
)
1033 struct ath_softc
*sc
= hw
->priv
;
1034 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1036 ath_dbg(common
, CONFIG
, "Detach Interface\n");
1038 mutex_lock(&sc
->mutex
);
1042 if (ath9k_uses_beacons(vif
->type
))
1043 ath9k_beacon_remove_slot(sc
, vif
);
1045 ath9k_ps_wakeup(sc
);
1046 ath9k_calculate_summary_state(hw
, NULL
);
1047 ath9k_ps_restore(sc
);
1049 mutex_unlock(&sc
->mutex
);
1052 static void ath9k_enable_ps(struct ath_softc
*sc
)
1054 struct ath_hw
*ah
= sc
->sc_ah
;
1055 struct ath_common
*common
= ath9k_hw_common(ah
);
1057 sc
->ps_enabled
= true;
1058 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
1059 if ((ah
->imask
& ATH9K_INT_TIM_TIMER
) == 0) {
1060 ah
->imask
|= ATH9K_INT_TIM_TIMER
;
1061 ath9k_hw_set_interrupts(ah
);
1063 ath9k_hw_setrxabort(ah
, 1);
1065 ath_dbg(common
, PS
, "PowerSave enabled\n");
1068 static void ath9k_disable_ps(struct ath_softc
*sc
)
1070 struct ath_hw
*ah
= sc
->sc_ah
;
1071 struct ath_common
*common
= ath9k_hw_common(ah
);
1073 sc
->ps_enabled
= false;
1074 ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
);
1075 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
1076 ath9k_hw_setrxabort(ah
, 0);
1077 sc
->ps_flags
&= ~(PS_WAIT_FOR_BEACON
|
1079 PS_WAIT_FOR_PSPOLL_DATA
|
1080 PS_WAIT_FOR_TX_ACK
);
1081 if (ah
->imask
& ATH9K_INT_TIM_TIMER
) {
1082 ah
->imask
&= ~ATH9K_INT_TIM_TIMER
;
1083 ath9k_hw_set_interrupts(ah
);
1086 ath_dbg(common
, PS
, "PowerSave disabled\n");
1089 static int ath9k_config(struct ieee80211_hw
*hw
, u32 changed
)
1091 struct ath_softc
*sc
= hw
->priv
;
1092 struct ath_hw
*ah
= sc
->sc_ah
;
1093 struct ath_common
*common
= ath9k_hw_common(ah
);
1094 struct ieee80211_conf
*conf
= &hw
->conf
;
1095 bool reset_channel
= false;
1097 ath9k_ps_wakeup(sc
);
1098 mutex_lock(&sc
->mutex
);
1100 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1101 sc
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1103 ath_cancel_work(sc
);
1104 ath9k_stop_btcoex(sc
);
1106 ath9k_start_btcoex(sc
);
1108 * The chip needs a reset to properly wake up from
1111 reset_channel
= ah
->chip_fullsleep
;
1116 * We just prepare to enable PS. We have to wait until our AP has
1117 * ACK'd our null data frame to disable RX otherwise we'll ignore
1118 * those ACKs and end up retransmitting the same null data frames.
1119 * IEEE80211_CONF_CHANGE_PS is only passed by mac80211 for STA mode.
1121 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1122 unsigned long flags
;
1123 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1124 if (conf
->flags
& IEEE80211_CONF_PS
)
1125 ath9k_enable_ps(sc
);
1127 ath9k_disable_ps(sc
);
1128 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1131 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1132 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1133 ath_dbg(common
, CONFIG
, "Monitor mode is enabled\n");
1134 sc
->sc_ah
->is_monitoring
= true;
1136 ath_dbg(common
, CONFIG
, "Monitor mode is disabled\n");
1137 sc
->sc_ah
->is_monitoring
= false;
1141 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) || reset_channel
) {
1142 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1143 int pos
= curchan
->hw_value
;
1145 unsigned long flags
;
1148 old_pos
= ah
->curchan
- &ah
->channels
[0];
1150 ath_dbg(common
, CONFIG
, "Set channel: %d MHz type: %d\n",
1151 curchan
->center_freq
, conf
->channel_type
);
1153 /* update survey stats for the old channel before switching */
1154 spin_lock_irqsave(&common
->cc_lock
, flags
);
1155 ath_update_survey_stats(sc
);
1156 spin_unlock_irqrestore(&common
->cc_lock
, flags
);
1159 * Preserve the current channel values, before updating
1162 if (ah
->curchan
&& (old_pos
== pos
))
1163 ath9k_hw_getnf(ah
, ah
->curchan
);
1165 ath9k_cmn_update_ichannel(&sc
->sc_ah
->channels
[pos
],
1166 curchan
, conf
->channel_type
);
1169 * If the operating channel changes, change the survey in-use flags
1171 * Reset the survey data for the new channel, unless we're switching
1172 * back to the operating channel from an off-channel operation.
1174 if (!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
) &&
1175 sc
->cur_survey
!= &sc
->survey
[pos
]) {
1178 sc
->cur_survey
->filled
&= ~SURVEY_INFO_IN_USE
;
1180 sc
->cur_survey
= &sc
->survey
[pos
];
1182 memset(sc
->cur_survey
, 0, sizeof(struct survey_info
));
1183 sc
->cur_survey
->filled
|= SURVEY_INFO_IN_USE
;
1184 } else if (!(sc
->survey
[pos
].filled
& SURVEY_INFO_IN_USE
)) {
1185 memset(&sc
->survey
[pos
], 0, sizeof(struct survey_info
));
1188 if (ath_set_channel(sc
, hw
, &sc
->sc_ah
->channels
[pos
]) < 0) {
1189 ath_err(common
, "Unable to set channel\n");
1190 mutex_unlock(&sc
->mutex
);
1191 ath9k_ps_restore(sc
);
1196 * The most recent snapshot of channel->noisefloor for the old
1197 * channel is only available after the hardware reset. Copy it to
1198 * the survey stats now.
1201 ath_update_survey_nf(sc
, old_pos
);
1204 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1205 ath_dbg(common
, CONFIG
, "Set power: %d\n", conf
->power_level
);
1206 sc
->config
.txpowlimit
= 2 * conf
->power_level
;
1207 ath9k_cmn_update_txpow(ah
, sc
->curtxpow
,
1208 sc
->config
.txpowlimit
, &sc
->curtxpow
);
1211 mutex_unlock(&sc
->mutex
);
1212 ath9k_ps_restore(sc
);
1217 #define SUPPORTED_FILTERS \
1218 (FIF_PROMISC_IN_BSS | \
1223 FIF_BCN_PRBRESP_PROMISC | \
1227 /* FIXME: sc->sc_full_reset ? */
1228 static void ath9k_configure_filter(struct ieee80211_hw
*hw
,
1229 unsigned int changed_flags
,
1230 unsigned int *total_flags
,
1233 struct ath_softc
*sc
= hw
->priv
;
1236 changed_flags
&= SUPPORTED_FILTERS
;
1237 *total_flags
&= SUPPORTED_FILTERS
;
1239 sc
->rx
.rxfilter
= *total_flags
;
1240 ath9k_ps_wakeup(sc
);
1241 rfilt
= ath_calcrxfilter(sc
);
1242 ath9k_hw_setrxfilter(sc
->sc_ah
, rfilt
);
1243 ath9k_ps_restore(sc
);
1245 ath_dbg(ath9k_hw_common(sc
->sc_ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1249 static int ath9k_sta_add(struct ieee80211_hw
*hw
,
1250 struct ieee80211_vif
*vif
,
1251 struct ieee80211_sta
*sta
)
1253 struct ath_softc
*sc
= hw
->priv
;
1254 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1255 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1256 struct ieee80211_key_conf ps_key
= { };
1258 ath_node_attach(sc
, sta
, vif
);
1260 if (vif
->type
!= NL80211_IFTYPE_AP
&&
1261 vif
->type
!= NL80211_IFTYPE_AP_VLAN
)
1264 an
->ps_key
= ath_key_config(common
, vif
, sta
, &ps_key
);
1269 static void ath9k_del_ps_key(struct ath_softc
*sc
,
1270 struct ieee80211_vif
*vif
,
1271 struct ieee80211_sta
*sta
)
1273 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1274 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1275 struct ieee80211_key_conf ps_key
= { .hw_key_idx
= an
->ps_key
};
1280 ath_key_delete(common
, &ps_key
);
1283 static int ath9k_sta_remove(struct ieee80211_hw
*hw
,
1284 struct ieee80211_vif
*vif
,
1285 struct ieee80211_sta
*sta
)
1287 struct ath_softc
*sc
= hw
->priv
;
1289 ath9k_del_ps_key(sc
, vif
, sta
);
1290 ath_node_detach(sc
, sta
);
1295 static void ath9k_sta_notify(struct ieee80211_hw
*hw
,
1296 struct ieee80211_vif
*vif
,
1297 enum sta_notify_cmd cmd
,
1298 struct ieee80211_sta
*sta
)
1300 struct ath_softc
*sc
= hw
->priv
;
1301 struct ath_node
*an
= (struct ath_node
*) sta
->drv_priv
;
1303 if (!sta
->ht_cap
.ht_supported
)
1307 case STA_NOTIFY_SLEEP
:
1308 an
->sleeping
= true;
1309 ath_tx_aggr_sleep(sta
, sc
, an
);
1311 case STA_NOTIFY_AWAKE
:
1312 an
->sleeping
= false;
1313 ath_tx_aggr_wakeup(sc
, an
);
1318 static int ath9k_conf_tx(struct ieee80211_hw
*hw
,
1319 struct ieee80211_vif
*vif
, u16 queue
,
1320 const struct ieee80211_tx_queue_params
*params
)
1322 struct ath_softc
*sc
= hw
->priv
;
1323 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1324 struct ath_txq
*txq
;
1325 struct ath9k_tx_queue_info qi
;
1328 if (queue
>= WME_NUM_AC
)
1331 txq
= sc
->tx
.txq_map
[queue
];
1333 ath9k_ps_wakeup(sc
);
1334 mutex_lock(&sc
->mutex
);
1336 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1338 qi
.tqi_aifs
= params
->aifs
;
1339 qi
.tqi_cwmin
= params
->cw_min
;
1340 qi
.tqi_cwmax
= params
->cw_max
;
1341 qi
.tqi_burstTime
= params
->txop
* 32;
1343 ath_dbg(common
, CONFIG
,
1344 "Configure tx [queue/halq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1345 queue
, txq
->axq_qnum
, params
->aifs
, params
->cw_min
,
1346 params
->cw_max
, params
->txop
);
1348 ath_update_max_aggr_framelen(sc
, queue
, qi
.tqi_burstTime
);
1349 ret
= ath_txq_update(sc
, txq
->axq_qnum
, &qi
);
1351 ath_err(common
, "TXQ Update failed\n");
1353 mutex_unlock(&sc
->mutex
);
1354 ath9k_ps_restore(sc
);
1359 static int ath9k_set_key(struct ieee80211_hw
*hw
,
1360 enum set_key_cmd cmd
,
1361 struct ieee80211_vif
*vif
,
1362 struct ieee80211_sta
*sta
,
1363 struct ieee80211_key_conf
*key
)
1365 struct ath_softc
*sc
= hw
->priv
;
1366 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1369 if (ath9k_modparam_nohwcrypt
)
1372 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1373 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1374 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1375 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1376 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1378 * For now, disable hw crypto for the RSN IBSS group keys. This
1379 * could be optimized in the future to use a modified key cache
1380 * design to support per-STA RX GTK, but until that gets
1381 * implemented, use of software crypto for group addressed
1382 * frames is a acceptable to allow RSN IBSS to be used.
1387 mutex_lock(&sc
->mutex
);
1388 ath9k_ps_wakeup(sc
);
1389 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1394 ath9k_del_ps_key(sc
, vif
, sta
);
1396 ret
= ath_key_config(common
, vif
, sta
, key
);
1398 key
->hw_key_idx
= ret
;
1399 /* push IV and Michael MIC generation to stack */
1400 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1401 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1402 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1403 if (sc
->sc_ah
->sw_mgmt_crypto
&&
1404 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1405 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1410 ath_key_delete(common
, key
);
1416 ath9k_ps_restore(sc
);
1417 mutex_unlock(&sc
->mutex
);
1422 static void ath9k_set_assoc_state(struct ath_softc
*sc
,
1423 struct ieee80211_vif
*vif
)
1425 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1426 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1427 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1428 unsigned long flags
;
1430 set_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
);
1431 avp
->primary_sta_vif
= true;
1434 * Set the AID, BSSID and do beacon-sync only when
1435 * the HW opmode is STATION.
1437 * But the primary bit is set above in any case.
1439 if (sc
->sc_ah
->opmode
!= NL80211_IFTYPE_STATION
)
1442 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1443 common
->curaid
= bss_conf
->aid
;
1444 ath9k_hw_write_associd(sc
->sc_ah
);
1446 sc
->last_rssi
= ATH_RSSI_DUMMY_MARKER
;
1447 sc
->sc_ah
->stats
.avgbrssi
= ATH_RSSI_DUMMY_MARKER
;
1449 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
1450 sc
->ps_flags
|= PS_BEACON_SYNC
| PS_WAIT_FOR_BEACON
;
1451 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
1453 ath_dbg(common
, CONFIG
,
1454 "Primary Station interface: %pM, BSSID: %pM\n",
1455 vif
->addr
, common
->curbssid
);
1458 static void ath9k_bss_assoc_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1460 struct ath_softc
*sc
= data
;
1461 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1463 if (test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
))
1466 if (bss_conf
->assoc
)
1467 ath9k_set_assoc_state(sc
, vif
);
1470 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
1471 struct ieee80211_vif
*vif
,
1472 struct ieee80211_bss_conf
*bss_conf
,
1476 (BSS_CHANGED_ASSOC | \
1477 BSS_CHANGED_IBSS | \
1478 BSS_CHANGED_BEACON_ENABLED)
1480 struct ath_softc
*sc
= hw
->priv
;
1481 struct ath_hw
*ah
= sc
->sc_ah
;
1482 struct ath_common
*common
= ath9k_hw_common(ah
);
1483 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1486 ath9k_ps_wakeup(sc
);
1487 mutex_lock(&sc
->mutex
);
1489 if (changed
& BSS_CHANGED_ASSOC
) {
1490 ath_dbg(common
, CONFIG
, "BSSID %pM Changed ASSOC %d\n",
1491 bss_conf
->bssid
, bss_conf
->assoc
);
1493 if (avp
->primary_sta_vif
&& !bss_conf
->assoc
) {
1494 clear_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
);
1495 avp
->primary_sta_vif
= false;
1497 if (ah
->opmode
== NL80211_IFTYPE_STATION
)
1498 clear_bit(SC_OP_BEACONS
, &sc
->sc_flags
);
1501 ieee80211_iterate_active_interfaces_atomic(sc
->hw
,
1502 ath9k_bss_assoc_iter
, sc
);
1504 if (!test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
) &&
1505 ah
->opmode
== NL80211_IFTYPE_STATION
) {
1506 memset(common
->curbssid
, 0, ETH_ALEN
);
1508 ath9k_hw_write_associd(sc
->sc_ah
);
1512 if (changed
& BSS_CHANGED_IBSS
) {
1513 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1514 common
->curaid
= bss_conf
->aid
;
1515 ath9k_hw_write_associd(sc
->sc_ah
);
1518 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) ||
1519 (changed
& BSS_CHANGED_BEACON_INT
)) {
1520 if (ah
->opmode
== NL80211_IFTYPE_AP
&&
1521 bss_conf
->enable_beacon
)
1522 ath9k_set_tsfadjust(sc
, vif
);
1523 if (ath9k_allow_beacon_config(sc
, vif
))
1524 ath9k_beacon_config(sc
, vif
, changed
);
1527 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1528 if (bss_conf
->use_short_slot
)
1532 if (vif
->type
== NL80211_IFTYPE_AP
) {
1534 * Defer update, so that connected stations can adjust
1535 * their settings at the same time.
1536 * See beacon.c for more details
1538 sc
->beacon
.slottime
= slottime
;
1539 sc
->beacon
.updateslot
= UPDATE
;
1541 ah
->slottime
= slottime
;
1542 ath9k_hw_init_global_settings(ah
);
1546 if (changed
& CHECK_ANI
)
1549 mutex_unlock(&sc
->mutex
);
1550 ath9k_ps_restore(sc
);
1555 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1557 struct ath_softc
*sc
= hw
->priv
;
1560 mutex_lock(&sc
->mutex
);
1561 ath9k_ps_wakeup(sc
);
1562 tsf
= ath9k_hw_gettsf64(sc
->sc_ah
);
1563 ath9k_ps_restore(sc
);
1564 mutex_unlock(&sc
->mutex
);
1569 static void ath9k_set_tsf(struct ieee80211_hw
*hw
,
1570 struct ieee80211_vif
*vif
,
1573 struct ath_softc
*sc
= hw
->priv
;
1575 mutex_lock(&sc
->mutex
);
1576 ath9k_ps_wakeup(sc
);
1577 ath9k_hw_settsf64(sc
->sc_ah
, tsf
);
1578 ath9k_ps_restore(sc
);
1579 mutex_unlock(&sc
->mutex
);
1582 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1584 struct ath_softc
*sc
= hw
->priv
;
1586 mutex_lock(&sc
->mutex
);
1588 ath9k_ps_wakeup(sc
);
1589 ath9k_hw_reset_tsf(sc
->sc_ah
);
1590 ath9k_ps_restore(sc
);
1592 mutex_unlock(&sc
->mutex
);
1595 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
1596 struct ieee80211_vif
*vif
,
1597 enum ieee80211_ampdu_mlme_action action
,
1598 struct ieee80211_sta
*sta
,
1599 u16 tid
, u16
*ssn
, u8 buf_size
)
1601 struct ath_softc
*sc
= hw
->priv
;
1607 case IEEE80211_AMPDU_RX_START
:
1609 case IEEE80211_AMPDU_RX_STOP
:
1611 case IEEE80211_AMPDU_TX_START
:
1612 ath9k_ps_wakeup(sc
);
1613 ret
= ath_tx_aggr_start(sc
, sta
, tid
, ssn
);
1615 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1616 ath9k_ps_restore(sc
);
1618 case IEEE80211_AMPDU_TX_STOP
:
1619 ath9k_ps_wakeup(sc
);
1620 ath_tx_aggr_stop(sc
, sta
, tid
);
1621 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1622 ath9k_ps_restore(sc
);
1624 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1625 ath9k_ps_wakeup(sc
);
1626 ath_tx_aggr_resume(sc
, sta
, tid
);
1627 ath9k_ps_restore(sc
);
1630 ath_err(ath9k_hw_common(sc
->sc_ah
), "Unknown AMPDU action\n");
1638 static int ath9k_get_survey(struct ieee80211_hw
*hw
, int idx
,
1639 struct survey_info
*survey
)
1641 struct ath_softc
*sc
= hw
->priv
;
1642 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1643 struct ieee80211_supported_band
*sband
;
1644 struct ieee80211_channel
*chan
;
1645 unsigned long flags
;
1648 spin_lock_irqsave(&common
->cc_lock
, flags
);
1650 ath_update_survey_stats(sc
);
1652 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
1653 if (sband
&& idx
>= sband
->n_channels
) {
1654 idx
-= sband
->n_channels
;
1659 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
1661 if (!sband
|| idx
>= sband
->n_channels
) {
1662 spin_unlock_irqrestore(&common
->cc_lock
, flags
);
1666 chan
= &sband
->channels
[idx
];
1667 pos
= chan
->hw_value
;
1668 memcpy(survey
, &sc
->survey
[pos
], sizeof(*survey
));
1669 survey
->channel
= chan
;
1670 spin_unlock_irqrestore(&common
->cc_lock
, flags
);
1675 static void ath9k_set_coverage_class(struct ieee80211_hw
*hw
, u8 coverage_class
)
1677 struct ath_softc
*sc
= hw
->priv
;
1678 struct ath_hw
*ah
= sc
->sc_ah
;
1680 mutex_lock(&sc
->mutex
);
1681 ah
->coverage_class
= coverage_class
;
1683 ath9k_ps_wakeup(sc
);
1684 ath9k_hw_init_global_settings(ah
);
1685 ath9k_ps_restore(sc
);
1687 mutex_unlock(&sc
->mutex
);
1690 static void ath9k_flush(struct ieee80211_hw
*hw
, bool drop
)
1692 struct ath_softc
*sc
= hw
->priv
;
1693 struct ath_hw
*ah
= sc
->sc_ah
;
1694 struct ath_common
*common
= ath9k_hw_common(ah
);
1695 int timeout
= 200; /* ms */
1699 mutex_lock(&sc
->mutex
);
1700 cancel_delayed_work_sync(&sc
->tx_complete_work
);
1702 if (ah
->ah_flags
& AH_UNPLUGGED
) {
1703 ath_dbg(common
, ANY
, "Device has been unplugged!\n");
1704 mutex_unlock(&sc
->mutex
);
1708 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
1709 ath_dbg(common
, ANY
, "Device not present\n");
1710 mutex_unlock(&sc
->mutex
);
1714 for (j
= 0; j
< timeout
; j
++) {
1718 usleep_range(1000, 2000);
1720 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1721 if (!ATH_TXQ_SETUP(sc
, i
))
1724 npend
= ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]);
1735 ath9k_ps_wakeup(sc
);
1736 spin_lock_bh(&sc
->sc_pcu_lock
);
1737 drain_txq
= ath_drain_all_txq(sc
, false);
1738 spin_unlock_bh(&sc
->sc_pcu_lock
);
1741 ath_reset(sc
, false);
1743 ath9k_ps_restore(sc
);
1744 ieee80211_wake_queues(hw
);
1747 ieee80211_queue_delayed_work(hw
, &sc
->tx_complete_work
, 0);
1748 mutex_unlock(&sc
->mutex
);
1751 static bool ath9k_tx_frames_pending(struct ieee80211_hw
*hw
)
1753 struct ath_softc
*sc
= hw
->priv
;
1756 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1757 if (!ATH_TXQ_SETUP(sc
, i
))
1760 if (ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]))
1766 static int ath9k_tx_last_beacon(struct ieee80211_hw
*hw
)
1768 struct ath_softc
*sc
= hw
->priv
;
1769 struct ath_hw
*ah
= sc
->sc_ah
;
1770 struct ieee80211_vif
*vif
;
1771 struct ath_vif
*avp
;
1773 struct ath_tx_status ts
;
1774 bool edma
= !!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
);
1777 vif
= sc
->beacon
.bslot
[0];
1781 if (!vif
->bss_conf
.enable_beacon
)
1784 avp
= (void *)vif
->drv_priv
;
1786 if (!sc
->beacon
.tx_processed
&& !edma
) {
1787 tasklet_disable(&sc
->bcon_tasklet
);
1790 if (!bf
|| !bf
->bf_mpdu
)
1793 status
= ath9k_hw_txprocdesc(ah
, bf
->bf_desc
, &ts
);
1794 if (status
== -EINPROGRESS
)
1797 sc
->beacon
.tx_processed
= true;
1798 sc
->beacon
.tx_last
= !(ts
.ts_status
& ATH9K_TXERR_MASK
);
1801 tasklet_enable(&sc
->bcon_tasklet
);
1804 return sc
->beacon
.tx_last
;
1807 static int ath9k_get_stats(struct ieee80211_hw
*hw
,
1808 struct ieee80211_low_level_stats
*stats
)
1810 struct ath_softc
*sc
= hw
->priv
;
1811 struct ath_hw
*ah
= sc
->sc_ah
;
1812 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1814 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1815 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1816 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1817 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1821 static u32
fill_chainmask(u32 cap
, u32
new)
1826 for (i
= 0; cap
&& new; i
++, cap
>>= 1) {
1827 if (!(cap
& BIT(0)))
1839 static bool validate_antenna_mask(struct ath_hw
*ah
, u32 val
)
1841 switch (val
& 0x7) {
1847 return (ah
->caps
.rx_chainmask
== 1);
1853 static int ath9k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
1855 struct ath_softc
*sc
= hw
->priv
;
1856 struct ath_hw
*ah
= sc
->sc_ah
;
1858 if (ah
->caps
.rx_chainmask
!= 1)
1861 if (!validate_antenna_mask(ah
, rx_ant
) || !tx_ant
)
1864 sc
->ant_rx
= rx_ant
;
1865 sc
->ant_tx
= tx_ant
;
1867 if (ah
->caps
.rx_chainmask
== 1)
1870 /* AR9100 runs into calibration issues if not all rx chains are enabled */
1871 if (AR_SREV_9100(ah
))
1872 ah
->rxchainmask
= 0x7;
1874 ah
->rxchainmask
= fill_chainmask(ah
->caps
.rx_chainmask
, rx_ant
);
1876 ah
->txchainmask
= fill_chainmask(ah
->caps
.tx_chainmask
, tx_ant
);
1877 ath9k_reload_chainmask_settings(sc
);
1882 static int ath9k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
1884 struct ath_softc
*sc
= hw
->priv
;
1886 *tx_ant
= sc
->ant_tx
;
1887 *rx_ant
= sc
->ant_rx
;
1891 #ifdef CONFIG_ATH9K_DEBUGFS
1893 /* Ethtool support for get-stats */
1895 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1896 static const char ath9k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1903 AMKSTR(d_tx_mpdus_queued
),
1904 AMKSTR(d_tx_mpdus_completed
),
1905 AMKSTR(d_tx_mpdu_xretries
),
1906 AMKSTR(d_tx_aggregates
),
1907 AMKSTR(d_tx_ampdus_queued_hw
),
1908 AMKSTR(d_tx_ampdus_queued_sw
),
1909 AMKSTR(d_tx_ampdus_completed
),
1910 AMKSTR(d_tx_ampdu_retries
),
1911 AMKSTR(d_tx_ampdu_xretries
),
1912 AMKSTR(d_tx_fifo_underrun
),
1913 AMKSTR(d_tx_op_exceeded
),
1914 AMKSTR(d_tx_timer_expiry
),
1915 AMKSTR(d_tx_desc_cfg_err
),
1916 AMKSTR(d_tx_data_underrun
),
1917 AMKSTR(d_tx_delim_underrun
),
1919 "d_rx_decrypt_crc_err",
1922 "d_rx_pre_delim_crc_err",
1923 "d_rx_post_delim_crc_err",
1924 "d_rx_decrypt_busy_err",
1926 "d_rx_phyerr_radar",
1927 "d_rx_phyerr_ofdm_timing",
1928 "d_rx_phyerr_cck_timing",
1931 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1933 static void ath9k_get_et_strings(struct ieee80211_hw
*hw
,
1934 struct ieee80211_vif
*vif
,
1937 if (sset
== ETH_SS_STATS
)
1938 memcpy(data
, *ath9k_gstrings_stats
,
1939 sizeof(ath9k_gstrings_stats
));
1942 static int ath9k_get_et_sset_count(struct ieee80211_hw
*hw
,
1943 struct ieee80211_vif
*vif
, int sset
)
1945 if (sset
== ETH_SS_STATS
)
1946 return ATH9K_SSTATS_LEN
;
1950 #define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
1951 #define AWDATA(elem) \
1953 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem; \
1954 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem; \
1955 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem; \
1956 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem; \
1959 #define AWDATA_RX(elem) \
1961 data[i++] = sc->debug.stats.rxstats.elem; \
1964 static void ath9k_get_et_stats(struct ieee80211_hw
*hw
,
1965 struct ieee80211_vif
*vif
,
1966 struct ethtool_stats
*stats
, u64
*data
)
1968 struct ath_softc
*sc
= hw
->priv
;
1971 data
[i
++] = (sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_BE
)].tx_pkts_all
+
1972 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_BK
)].tx_pkts_all
+
1973 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_VI
)].tx_pkts_all
+
1974 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_VO
)].tx_pkts_all
);
1975 data
[i
++] = (sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_BE
)].tx_bytes_all
+
1976 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_BK
)].tx_bytes_all
+
1977 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_VI
)].tx_bytes_all
+
1978 sc
->debug
.stats
.txstats
[PR_QNUM(WME_AC_VO
)].tx_bytes_all
);
1979 AWDATA_RX(rx_pkts_all
);
1980 AWDATA_RX(rx_bytes_all
);
1982 AWDATA(tx_pkts_all
);
1983 AWDATA(tx_bytes_all
);
1988 AWDATA(a_queued_hw
);
1989 AWDATA(a_queued_sw
);
1990 AWDATA(a_completed
);
1993 AWDATA(fifo_underrun
);
1996 AWDATA(desc_cfg_err
);
1997 AWDATA(data_underrun
);
1998 AWDATA(delim_underrun
);
2000 AWDATA_RX(decrypt_crc_err
);
2003 AWDATA_RX(pre_delim_crc_err
);
2004 AWDATA_RX(post_delim_crc_err
);
2005 AWDATA_RX(decrypt_busy_err
);
2007 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_RADAR
]);
2008 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_OFDM_TIMING
]);
2009 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_CCK_TIMING
]);
2011 WARN_ON(i
!= ATH9K_SSTATS_LEN
);
2014 /* End of ethtool get-stats functions */
2019 #ifdef CONFIG_PM_SLEEP
2021 static void ath9k_wow_map_triggers(struct ath_softc
*sc
,
2022 struct cfg80211_wowlan
*wowlan
,
2025 if (wowlan
->disconnect
)
2026 *wow_triggers
|= AH_WOW_LINK_CHANGE
|
2028 if (wowlan
->magic_pkt
)
2029 *wow_triggers
|= AH_WOW_MAGIC_PATTERN_EN
;
2031 if (wowlan
->n_patterns
)
2032 *wow_triggers
|= AH_WOW_USER_PATTERN_EN
;
2034 sc
->wow_enabled
= *wow_triggers
;
2038 static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc
*sc
)
2040 struct ath_hw
*ah
= sc
->sc_ah
;
2041 struct ath_common
*common
= ath9k_hw_common(ah
);
2042 struct ath9k_hw_capabilities
*pcaps
= &ah
->caps
;
2043 int pattern_count
= 0;
2045 u8 dis_deauth_pattern
[MAX_PATTERN_SIZE
];
2046 u8 dis_deauth_mask
[MAX_PATTERN_SIZE
];
2048 memset(dis_deauth_pattern
, 0, MAX_PATTERN_SIZE
);
2049 memset(dis_deauth_mask
, 0, MAX_PATTERN_SIZE
);
2052 * Create Dissassociate / Deauthenticate packet filter
2054 * 2 bytes 2 byte 6 bytes 6 bytes 6 bytes
2055 * +--------------+----------+---------+--------+--------+----
2056 * + Frame Control+ Duration + DA + SA + BSSID +
2057 * +--------------+----------+---------+--------+--------+----
2059 * The above is the management frame format for disassociate/
2060 * deauthenticate pattern, from this we need to match the first byte
2061 * of 'Frame Control' and DA, SA, and BSSID fields
2062 * (skipping 2nd byte of FC and Duration feild.
2064 * Disassociate pattern
2065 * --------------------
2066 * Frame control = 00 00 1010
2067 * DA, SA, BSSID = x:x:x:x:x:x
2068 * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
2069 * | x:x:x:x:x:x -- 22 bytes
2071 * Deauthenticate pattern
2072 * ----------------------
2073 * Frame control = 00 00 1100
2074 * DA, SA, BSSID = x:x:x:x:x:x
2075 * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
2076 * | x:x:x:x:x:x -- 22 bytes
2079 /* Create Disassociate Pattern first */
2083 /* Fill out the mask with all FF's */
2085 for (i
= 0; i
< MAX_PATTERN_MASK_SIZE
; i
++)
2086 dis_deauth_mask
[i
] = 0xff;
2088 /* copy the first byte of frame control field */
2089 dis_deauth_pattern
[byte_cnt
] = 0xa0;
2092 /* skip 2nd byte of frame control and Duration field */
2096 * need not match the destination mac address, it can be a broadcast
2097 * mac address or an unicast to this station
2101 /* copy the source mac address */
2102 memcpy((dis_deauth_pattern
+ byte_cnt
), common
->curbssid
, ETH_ALEN
);
2106 /* copy the bssid, its same as the source mac address */
2108 memcpy((dis_deauth_pattern
+ byte_cnt
), common
->curbssid
, ETH_ALEN
);
2110 /* Create Disassociate pattern mask */
2112 if (pcaps
->hw_caps
& ATH9K_HW_WOW_PATTERN_MATCH_EXACT
) {
2114 if (pcaps
->hw_caps
& ATH9K_HW_WOW_PATTERN_MATCH_DWORD
) {
2116 * for AR9280, because of hardware limitation, the
2117 * first 4 bytes have to be matched for all patterns.
2118 * the mask for disassociation and de-auth pattern
2119 * matching need to enable the first 4 bytes.
2120 * also the duration field needs to be filled.
2122 dis_deauth_mask
[0] = 0xf0;
2125 * fill in duration field
2126 FIXME: what is the exact value ?
2128 dis_deauth_pattern
[2] = 0xff;
2129 dis_deauth_pattern
[3] = 0xff;
2131 dis_deauth_mask
[0] = 0xfe;
2134 dis_deauth_mask
[1] = 0x03;
2135 dis_deauth_mask
[2] = 0xc0;
2137 dis_deauth_mask
[0] = 0xef;
2138 dis_deauth_mask
[1] = 0x3f;
2139 dis_deauth_mask
[2] = 0x00;
2140 dis_deauth_mask
[3] = 0xfc;
2143 ath_dbg(common
, WOW
, "Adding disassoc/deauth patterns for WoW\n");
2145 ath9k_hw_wow_apply_pattern(ah
, dis_deauth_pattern
, dis_deauth_mask
,
2146 pattern_count
, byte_cnt
);
2150 * for de-authenticate pattern, only the first byte of the frame
2151 * control field gets changed from 0xA0 to 0xC0
2153 dis_deauth_pattern
[0] = 0xC0;
2155 ath9k_hw_wow_apply_pattern(ah
, dis_deauth_pattern
, dis_deauth_mask
,
2156 pattern_count
, byte_cnt
);
2160 static void ath9k_wow_add_pattern(struct ath_softc
*sc
,
2161 struct cfg80211_wowlan
*wowlan
)
2163 struct ath_hw
*ah
= sc
->sc_ah
;
2164 struct ath9k_wow_pattern
*wow_pattern
= NULL
;
2165 struct cfg80211_wowlan_trig_pkt_pattern
*patterns
= wowlan
->patterns
;
2169 if (!wowlan
->n_patterns
)
2173 * Add the new user configured patterns
2175 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
2177 wow_pattern
= kzalloc(sizeof(*wow_pattern
), GFP_KERNEL
);
2183 * TODO: convert the generic user space pattern to
2184 * appropriate chip specific/802.11 pattern.
2187 mask_len
= DIV_ROUND_UP(wowlan
->patterns
[i
].pattern_len
, 8);
2188 memset(wow_pattern
->pattern_bytes
, 0, MAX_PATTERN_SIZE
);
2189 memset(wow_pattern
->mask_bytes
, 0, MAX_PATTERN_SIZE
);
2190 memcpy(wow_pattern
->pattern_bytes
, patterns
[i
].pattern
,
2191 patterns
[i
].pattern_len
);
2192 memcpy(wow_pattern
->mask_bytes
, patterns
[i
].mask
, mask_len
);
2193 wow_pattern
->pattern_len
= patterns
[i
].pattern_len
;
2196 * just need to take care of deauth and disssoc pattern,
2197 * make sure we don't overwrite them.
2200 ath9k_hw_wow_apply_pattern(ah
, wow_pattern
->pattern_bytes
,
2201 wow_pattern
->mask_bytes
,
2203 wow_pattern
->pattern_len
);
2210 static int ath9k_suspend(struct ieee80211_hw
*hw
,
2211 struct cfg80211_wowlan
*wowlan
)
2213 struct ath_softc
*sc
= hw
->priv
;
2214 struct ath_hw
*ah
= sc
->sc_ah
;
2215 struct ath_common
*common
= ath9k_hw_common(ah
);
2216 u32 wow_triggers_enabled
= 0;
2219 mutex_lock(&sc
->mutex
);
2221 ath_cancel_work(sc
);
2223 del_timer_sync(&sc
->rx_poll_timer
);
2225 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
2226 ath_dbg(common
, ANY
, "Device not present\n");
2231 if (WARN_ON(!wowlan
)) {
2232 ath_dbg(common
, WOW
, "None of the WoW triggers enabled\n");
2237 if (!device_can_wakeup(sc
->dev
)) {
2238 ath_dbg(common
, WOW
, "device_can_wakeup failed, WoW is not enabled\n");
2244 * none of the sta vifs are associated
2245 * and we are not currently handling multivif
2246 * cases, for instance we have to seperately
2247 * configure 'keep alive frame' for each
2251 if (!test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
)) {
2252 ath_dbg(common
, WOW
, "None of the STA vifs are associated\n");
2257 if (sc
->nvifs
> 1) {
2258 ath_dbg(common
, WOW
, "WoW for multivif is not yet supported\n");
2263 ath9k_wow_map_triggers(sc
, wowlan
, &wow_triggers_enabled
);
2265 ath_dbg(common
, WOW
, "WoW triggers enabled 0x%x\n",
2266 wow_triggers_enabled
);
2268 ath9k_ps_wakeup(sc
);
2270 ath9k_stop_btcoex(sc
);
2273 * Enable wake up on recieving disassoc/deauth
2276 ath9k_wow_add_disassoc_deauth_pattern(sc
);
2278 if (wow_triggers_enabled
& AH_WOW_USER_PATTERN_EN
)
2279 ath9k_wow_add_pattern(sc
, wowlan
);
2281 spin_lock_bh(&sc
->sc_pcu_lock
);
2283 * To avoid false wake, we enable beacon miss interrupt only
2284 * when we go to sleep. We save the current interrupt mask
2285 * so we can restore it after the system wakes up
2287 sc
->wow_intr_before_sleep
= ah
->imask
;
2288 ah
->imask
&= ~ATH9K_INT_GLOBAL
;
2289 ath9k_hw_disable_interrupts(ah
);
2290 ah
->imask
= ATH9K_INT_BMISS
| ATH9K_INT_GLOBAL
;
2291 ath9k_hw_set_interrupts(ah
);
2292 ath9k_hw_enable_interrupts(ah
);
2294 spin_unlock_bh(&sc
->sc_pcu_lock
);
2297 * we can now sync irq and kill any running tasklets, since we already
2298 * disabled interrupts and not holding a spin lock
2300 synchronize_irq(sc
->irq
);
2301 tasklet_kill(&sc
->intr_tq
);
2303 ath9k_hw_wow_enable(ah
, wow_triggers_enabled
);
2305 ath9k_ps_restore(sc
);
2306 ath_dbg(common
, ANY
, "WoW enabled in ath9k\n");
2307 atomic_inc(&sc
->wow_sleep_proc_intr
);
2310 mutex_unlock(&sc
->mutex
);
2314 static int ath9k_resume(struct ieee80211_hw
*hw
)
2316 struct ath_softc
*sc
= hw
->priv
;
2317 struct ath_hw
*ah
= sc
->sc_ah
;
2318 struct ath_common
*common
= ath9k_hw_common(ah
);
2321 mutex_lock(&sc
->mutex
);
2323 ath9k_ps_wakeup(sc
);
2325 spin_lock_bh(&sc
->sc_pcu_lock
);
2327 ath9k_hw_disable_interrupts(ah
);
2328 ah
->imask
= sc
->wow_intr_before_sleep
;
2329 ath9k_hw_set_interrupts(ah
);
2330 ath9k_hw_enable_interrupts(ah
);
2332 spin_unlock_bh(&sc
->sc_pcu_lock
);
2334 wow_status
= ath9k_hw_wow_wakeup(ah
);
2336 if (atomic_read(&sc
->wow_got_bmiss_intr
) == 0) {
2338 * some devices may not pick beacon miss
2339 * as the reason they woke up so we add
2340 * that here for that shortcoming.
2342 wow_status
|= AH_WOW_BEACON_MISS
;
2343 atomic_dec(&sc
->wow_got_bmiss_intr
);
2344 ath_dbg(common
, ANY
, "Beacon miss interrupt picked up during WoW sleep\n");
2347 atomic_dec(&sc
->wow_sleep_proc_intr
);
2350 ath_dbg(common
, ANY
, "Waking up due to WoW triggers %s with WoW status = %x\n",
2351 ath9k_hw_wow_event_to_string(wow_status
), wow_status
);
2354 ath_restart_work(sc
);
2355 ath9k_start_btcoex(sc
);
2357 ath9k_ps_restore(sc
);
2358 mutex_unlock(&sc
->mutex
);
2363 static void ath9k_set_wakeup(struct ieee80211_hw
*hw
, bool enabled
)
2365 struct ath_softc
*sc
= hw
->priv
;
2367 mutex_lock(&sc
->mutex
);
2368 device_init_wakeup(sc
->dev
, 1);
2369 device_set_wakeup_enable(sc
->dev
, enabled
);
2370 mutex_unlock(&sc
->mutex
);
2375 struct ieee80211_ops ath9k_ops
= {
2377 .start
= ath9k_start
,
2379 .add_interface
= ath9k_add_interface
,
2380 .change_interface
= ath9k_change_interface
,
2381 .remove_interface
= ath9k_remove_interface
,
2382 .config
= ath9k_config
,
2383 .configure_filter
= ath9k_configure_filter
,
2384 .sta_add
= ath9k_sta_add
,
2385 .sta_remove
= ath9k_sta_remove
,
2386 .sta_notify
= ath9k_sta_notify
,
2387 .conf_tx
= ath9k_conf_tx
,
2388 .bss_info_changed
= ath9k_bss_info_changed
,
2389 .set_key
= ath9k_set_key
,
2390 .get_tsf
= ath9k_get_tsf
,
2391 .set_tsf
= ath9k_set_tsf
,
2392 .reset_tsf
= ath9k_reset_tsf
,
2393 .ampdu_action
= ath9k_ampdu_action
,
2394 .get_survey
= ath9k_get_survey
,
2395 .rfkill_poll
= ath9k_rfkill_poll_state
,
2396 .set_coverage_class
= ath9k_set_coverage_class
,
2397 .flush
= ath9k_flush
,
2398 .tx_frames_pending
= ath9k_tx_frames_pending
,
2399 .tx_last_beacon
= ath9k_tx_last_beacon
,
2400 .get_stats
= ath9k_get_stats
,
2401 .set_antenna
= ath9k_set_antenna
,
2402 .get_antenna
= ath9k_get_antenna
,
2404 #ifdef CONFIG_PM_SLEEP
2405 .suspend
= ath9k_suspend
,
2406 .resume
= ath9k_resume
,
2407 .set_wakeup
= ath9k_set_wakeup
,
2410 #ifdef CONFIG_ATH9K_DEBUGFS
2411 .get_et_sset_count
= ath9k_get_et_sset_count
,
2412 .get_et_stats
= ath9k_get_et_stats
,
2413 .get_et_strings
= ath9k_get_et_strings
,