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 (ath9k_hw_mci_is_enabled(sc
->sc_ah
) &&
297 (sc
->hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
298 ath9k_mci_set_txpower(sc
, true, false);
300 if (!ath_complete_reset(sc
, true))
304 spin_unlock_bh(&sc
->sc_pcu_lock
);
310 * Set/change channels. If the channel is really being changed, it's done
311 * by reseting the chip. To accomplish this we must first cleanup any pending
312 * DMA, then restart stuff.
314 static int ath_set_channel(struct ath_softc
*sc
, struct ieee80211_hw
*hw
,
315 struct ath9k_channel
*hchan
)
319 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
))
322 r
= ath_reset_internal(sc
, hchan
, false);
327 static void ath_node_attach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
,
328 struct ieee80211_vif
*vif
)
332 an
= (struct ath_node
*)sta
->drv_priv
;
334 #ifdef CONFIG_ATH9K_DEBUGFS
335 spin_lock(&sc
->nodes_lock
);
336 list_add(&an
->list
, &sc
->nodes
);
337 spin_unlock(&sc
->nodes_lock
);
342 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
) {
343 ath_tx_node_init(sc
, an
);
344 an
->maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
345 sta
->ht_cap
.ampdu_factor
);
346 density
= ath9k_parse_mpdudensity(sta
->ht_cap
.ampdu_density
);
347 an
->mpdudensity
= density
;
351 static void ath_node_detach(struct ath_softc
*sc
, struct ieee80211_sta
*sta
)
353 struct ath_node
*an
= (struct ath_node
*)sta
->drv_priv
;
355 #ifdef CONFIG_ATH9K_DEBUGFS
356 spin_lock(&sc
->nodes_lock
);
358 spin_unlock(&sc
->nodes_lock
);
362 if (sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
363 ath_tx_node_cleanup(sc
, an
);
366 void ath9k_tasklet(unsigned long data
)
368 struct ath_softc
*sc
= (struct ath_softc
*)data
;
369 struct ath_hw
*ah
= sc
->sc_ah
;
370 struct ath_common
*common
= ath9k_hw_common(ah
);
371 enum ath_reset_type type
;
373 u32 status
= sc
->intrstatus
;
377 spin_lock(&sc
->sc_pcu_lock
);
379 if ((status
& ATH9K_INT_FATAL
) ||
380 (status
& ATH9K_INT_BB_WATCHDOG
)) {
382 if (status
& ATH9K_INT_FATAL
)
383 type
= RESET_TYPE_FATAL_INT
;
385 type
= RESET_TYPE_BB_WATCHDOG
;
387 ath9k_queue_reset(sc
, type
);
391 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
392 if ((status
& ATH9K_INT_TSFOOR
) && sc
->ps_enabled
) {
394 * TSF sync does not look correct; remain awake to sync with
397 ath_dbg(common
, PS
, "TSFOOR - Sync with next Beacon\n");
398 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
| PS_BEACON_SYNC
;
400 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
402 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
403 rxmask
= (ATH9K_INT_RXHP
| ATH9K_INT_RXLP
| ATH9K_INT_RXEOL
|
406 rxmask
= (ATH9K_INT_RX
| ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
408 if (status
& rxmask
) {
409 /* Check for high priority Rx first */
410 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) &&
411 (status
& ATH9K_INT_RXHP
))
412 ath_rx_tasklet(sc
, 0, true);
414 ath_rx_tasklet(sc
, 0, false);
417 if (status
& ATH9K_INT_TX
) {
418 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
419 ath_tx_edma_tasklet(sc
);
424 ath9k_btcoex_handle_interrupt(sc
, status
);
427 /* re-enable hardware interrupt */
428 ath9k_hw_enable_interrupts(ah
);
430 spin_unlock(&sc
->sc_pcu_lock
);
431 ath9k_ps_restore(sc
);
434 irqreturn_t
ath_isr(int irq
, void *dev
)
436 #define SCHED_INTR ( \
438 ATH9K_INT_BB_WATCHDOG | \
448 ATH9K_INT_GENTIMER | \
451 struct ath_softc
*sc
= dev
;
452 struct ath_hw
*ah
= sc
->sc_ah
;
453 struct ath_common
*common
= ath9k_hw_common(ah
);
454 enum ath9k_int status
;
458 * The hardware is not ready/present, don't
459 * touch anything. Note this can happen early
460 * on if the IRQ is shared.
462 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
))
465 /* shared irq, not for us */
467 if (!ath9k_hw_intrpend(ah
))
470 if (test_bit(SC_OP_HW_RESET
, &sc
->sc_flags
)) {
471 ath9k_hw_kill_interrupts(ah
);
476 * Figure out the reason(s) for the interrupt. Note
477 * that the hal returns a pseudo-ISR that may include
478 * bits we haven't explicitly enabled so we mask the
479 * value to insure we only process bits we requested.
481 ath9k_hw_getisr(ah
, &status
); /* NB: clears ISR too */
482 status
&= ah
->imask
; /* discard unasked-for bits */
485 * If there are no status bits set, then this interrupt was not
486 * for me (should have been caught above).
491 /* Cache the status */
492 sc
->intrstatus
= status
;
494 if (status
& SCHED_INTR
)
498 * If a FATAL or RXORN interrupt is received, we have to reset the
501 if ((status
& ATH9K_INT_FATAL
) || ((status
& ATH9K_INT_RXORN
) &&
502 !(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)))
505 if ((ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
) &&
506 (status
& ATH9K_INT_BB_WATCHDOG
)) {
508 spin_lock(&common
->cc_lock
);
509 ath_hw_cycle_counters_update(common
);
510 ar9003_hw_bb_watchdog_dbg_info(ah
);
511 spin_unlock(&common
->cc_lock
);
515 #ifdef CONFIG_PM_SLEEP
516 if (status
& ATH9K_INT_BMISS
) {
517 if (atomic_read(&sc
->wow_sleep_proc_intr
) == 0) {
518 ath_dbg(common
, ANY
, "during WoW we got a BMISS\n");
519 atomic_inc(&sc
->wow_got_bmiss_intr
);
520 atomic_dec(&sc
->wow_sleep_proc_intr
);
524 if (status
& ATH9K_INT_SWBA
)
525 tasklet_schedule(&sc
->bcon_tasklet
);
527 if (status
& ATH9K_INT_TXURN
)
528 ath9k_hw_updatetxtriglevel(ah
, true);
530 if (status
& ATH9K_INT_RXEOL
) {
531 ah
->imask
&= ~(ATH9K_INT_RXEOL
| ATH9K_INT_RXORN
);
532 ath9k_hw_set_interrupts(ah
);
535 if (!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
536 if (status
& ATH9K_INT_TIM_TIMER
) {
537 if (ATH_DBG_WARN_ON_ONCE(sc
->ps_idle
))
539 /* Clear RxAbort bit so that we can
541 ath9k_setpower(sc
, ATH9K_PM_AWAKE
);
542 spin_lock(&sc
->sc_pm_lock
);
543 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
544 sc
->ps_flags
|= PS_WAIT_FOR_BEACON
;
545 spin_unlock(&sc
->sc_pm_lock
);
550 ath_debug_stat_interrupt(sc
, status
);
553 /* turn off every interrupt */
554 ath9k_hw_disable_interrupts(ah
);
555 tasklet_schedule(&sc
->intr_tq
);
563 static int ath_reset(struct ath_softc
*sc
, bool retry_tx
)
569 r
= ath_reset_internal(sc
, NULL
, retry_tx
);
573 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
574 if (ATH_TXQ_SETUP(sc
, i
)) {
575 spin_lock_bh(&sc
->tx
.txq
[i
].axq_lock
);
576 ath_txq_schedule(sc
, &sc
->tx
.txq
[i
]);
577 spin_unlock_bh(&sc
->tx
.txq
[i
].axq_lock
);
582 ath9k_ps_restore(sc
);
587 void ath9k_queue_reset(struct ath_softc
*sc
, enum ath_reset_type type
)
589 #ifdef CONFIG_ATH9K_DEBUGFS
590 RESET_STAT_INC(sc
, type
);
592 set_bit(SC_OP_HW_RESET
, &sc
->sc_flags
);
593 ieee80211_queue_work(sc
->hw
, &sc
->hw_reset_work
);
596 void ath_reset_work(struct work_struct
*work
)
598 struct ath_softc
*sc
= container_of(work
, struct ath_softc
, hw_reset_work
);
603 /**********************/
604 /* mac80211 callbacks */
605 /**********************/
607 static int ath9k_start(struct ieee80211_hw
*hw
)
609 struct ath_softc
*sc
= hw
->priv
;
610 struct ath_hw
*ah
= sc
->sc_ah
;
611 struct ath_common
*common
= ath9k_hw_common(ah
);
612 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
613 struct ath9k_channel
*init_channel
;
616 ath_dbg(common
, CONFIG
,
617 "Starting driver with initial channel: %d MHz\n",
618 curchan
->center_freq
);
621 mutex_lock(&sc
->mutex
);
623 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
625 /* Reset SERDES registers */
626 ath9k_hw_configpcipowersave(ah
, false);
629 * The basic interface to setting the hardware in a good
630 * state is ``reset''. On return the hardware is known to
631 * be powered up and with interrupts disabled. This must
632 * be followed by initialization of the appropriate bits
633 * and then setup of the interrupt mask.
635 spin_lock_bh(&sc
->sc_pcu_lock
);
637 atomic_set(&ah
->intr_ref_cnt
, -1);
639 r
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
642 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
643 r
, curchan
->center_freq
);
644 ah
->reset_power_on
= false;
647 /* Setup our intr mask. */
648 ah
->imask
= ATH9K_INT_TX
| ATH9K_INT_RXEOL
|
649 ATH9K_INT_RXORN
| ATH9K_INT_FATAL
|
652 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
)
653 ah
->imask
|= ATH9K_INT_RXHP
|
655 ATH9K_INT_BB_WATCHDOG
;
657 ah
->imask
|= ATH9K_INT_RX
;
659 ah
->imask
|= ATH9K_INT_GTT
;
661 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_HT
)
662 ah
->imask
|= ATH9K_INT_CST
;
666 clear_bit(SC_OP_INVALID
, &sc
->sc_flags
);
667 sc
->sc_ah
->is_monitoring
= false;
669 if (!ath_complete_reset(sc
, false))
670 ah
->reset_power_on
= false;
672 if (ah
->led_pin
>= 0) {
673 ath9k_hw_cfg_output(ah
, ah
->led_pin
,
674 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
675 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 0);
679 * Reset key cache to sane defaults (all entries cleared) instead of
680 * semi-random values after suspend/resume.
682 ath9k_cmn_init_crypto(sc
->sc_ah
);
684 spin_unlock_bh(&sc
->sc_pcu_lock
);
686 mutex_unlock(&sc
->mutex
);
688 ath9k_ps_restore(sc
);
693 static void ath9k_tx(struct ieee80211_hw
*hw
,
694 struct ieee80211_tx_control
*control
,
697 struct ath_softc
*sc
= hw
->priv
;
698 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
699 struct ath_tx_control txctl
;
700 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
703 if (sc
->ps_enabled
) {
705 * mac80211 does not set PM field for normal data frames, so we
706 * need to update that based on the current PS mode.
708 if (ieee80211_is_data(hdr
->frame_control
) &&
709 !ieee80211_is_nullfunc(hdr
->frame_control
) &&
710 !ieee80211_has_pm(hdr
->frame_control
)) {
712 "Add PM=1 for a TX frame while in PS mode\n");
713 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
717 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_NETWORK_SLEEP
)) {
719 * We are using PS-Poll and mac80211 can request TX while in
720 * power save mode. Need to wake up hardware for the TX to be
721 * completed and if needed, also for RX of buffered frames.
724 spin_lock_irqsave(&sc
->sc_pm_lock
, flags
);
725 if (!(sc
->sc_ah
->caps
.hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
726 ath9k_hw_setrxabort(sc
->sc_ah
, 0);
727 if (ieee80211_is_pspoll(hdr
->frame_control
)) {
729 "Sending PS-Poll to pick a buffered frame\n");
730 sc
->ps_flags
|= PS_WAIT_FOR_PSPOLL_DATA
;
732 ath_dbg(common
, PS
, "Wake up to complete TX\n");
733 sc
->ps_flags
|= PS_WAIT_FOR_TX_ACK
;
736 * The actual restore operation will happen only after
737 * the ps_flags bit is cleared. We are just dropping
738 * the ps_usecount here.
740 spin_unlock_irqrestore(&sc
->sc_pm_lock
, flags
);
741 ath9k_ps_restore(sc
);
745 * Cannot tx while the hardware is in full sleep, it first needs a full
746 * chip reset to recover from that
748 if (unlikely(sc
->sc_ah
->power_mode
== ATH9K_PM_FULL_SLEEP
)) {
749 ath_err(common
, "TX while HW is in FULL_SLEEP mode\n");
753 memset(&txctl
, 0, sizeof(struct ath_tx_control
));
754 txctl
.txq
= sc
->tx
.txq_map
[skb_get_queue_mapping(skb
)];
755 txctl
.sta
= control
->sta
;
757 ath_dbg(common
, XMIT
, "transmitting packet, skb: %p\n", skb
);
759 if (ath_tx_start(hw
, skb
, &txctl
) != 0) {
760 ath_dbg(common
, XMIT
, "TX failed\n");
761 TX_STAT_INC(txctl
.txq
->axq_qnum
, txfailed
);
767 ieee80211_free_txskb(hw
, skb
);
770 static void ath9k_stop(struct ieee80211_hw
*hw
)
772 struct ath_softc
*sc
= hw
->priv
;
773 struct ath_hw
*ah
= sc
->sc_ah
;
774 struct ath_common
*common
= ath9k_hw_common(ah
);
777 mutex_lock(&sc
->mutex
);
780 del_timer_sync(&sc
->rx_poll_timer
);
782 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
783 ath_dbg(common
, ANY
, "Device not present\n");
784 mutex_unlock(&sc
->mutex
);
788 /* Ensure HW is awake when we try to shut it down. */
791 spin_lock_bh(&sc
->sc_pcu_lock
);
793 /* prevent tasklets to enable interrupts once we disable them */
794 ah
->imask
&= ~ATH9K_INT_GLOBAL
;
796 /* make sure h/w will not generate any interrupt
797 * before setting the invalid flag. */
798 ath9k_hw_disable_interrupts(ah
);
800 spin_unlock_bh(&sc
->sc_pcu_lock
);
802 /* we can now sync irq and kill any running tasklets, since we already
803 * disabled interrupts and not holding a spin lock */
804 synchronize_irq(sc
->irq
);
805 tasklet_kill(&sc
->intr_tq
);
806 tasklet_kill(&sc
->bcon_tasklet
);
808 prev_idle
= sc
->ps_idle
;
811 spin_lock_bh(&sc
->sc_pcu_lock
);
813 if (ah
->led_pin
>= 0) {
814 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 1);
815 ath9k_hw_cfg_gpio_input(ah
, ah
->led_pin
);
818 ath_prepare_reset(sc
, false, true);
821 dev_kfree_skb_any(sc
->rx
.frag
);
826 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
828 ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
829 ath9k_hw_phy_disable(ah
);
831 ath9k_hw_configpcipowersave(ah
, true);
833 spin_unlock_bh(&sc
->sc_pcu_lock
);
835 ath9k_ps_restore(sc
);
837 set_bit(SC_OP_INVALID
, &sc
->sc_flags
);
838 sc
->ps_idle
= prev_idle
;
840 mutex_unlock(&sc
->mutex
);
842 ath_dbg(common
, CONFIG
, "Driver halt\n");
845 bool ath9k_uses_beacons(int type
)
848 case NL80211_IFTYPE_AP
:
849 case NL80211_IFTYPE_ADHOC
:
850 case NL80211_IFTYPE_MESH_POINT
:
857 static void ath9k_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
859 struct ath9k_vif_iter_data
*iter_data
= data
;
862 if (iter_data
->hw_macaddr
)
863 for (i
= 0; i
< ETH_ALEN
; i
++)
864 iter_data
->mask
[i
] &=
865 ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
868 case NL80211_IFTYPE_AP
:
871 case NL80211_IFTYPE_STATION
:
872 iter_data
->nstations
++;
874 case NL80211_IFTYPE_ADHOC
:
875 iter_data
->nadhocs
++;
877 case NL80211_IFTYPE_MESH_POINT
:
878 iter_data
->nmeshes
++;
880 case NL80211_IFTYPE_WDS
:
888 static void ath9k_sta_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
890 struct ath_softc
*sc
= data
;
891 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
893 if (vif
->type
!= NL80211_IFTYPE_STATION
)
896 if (avp
->primary_sta_vif
)
897 ath9k_set_assoc_state(sc
, vif
);
900 /* Called with sc->mutex held. */
901 void ath9k_calculate_iter_data(struct ieee80211_hw
*hw
,
902 struct ieee80211_vif
*vif
,
903 struct ath9k_vif_iter_data
*iter_data
)
905 struct ath_softc
*sc
= hw
->priv
;
906 struct ath_hw
*ah
= sc
->sc_ah
;
907 struct ath_common
*common
= ath9k_hw_common(ah
);
910 * Use the hardware MAC address as reference, the hardware uses it
911 * together with the BSSID mask when matching addresses.
913 memset(iter_data
, 0, sizeof(*iter_data
));
914 iter_data
->hw_macaddr
= common
->macaddr
;
915 memset(&iter_data
->mask
, 0xff, ETH_ALEN
);
918 ath9k_vif_iter(iter_data
, vif
->addr
, vif
);
920 /* Get list of all active MAC addresses */
921 ieee80211_iterate_active_interfaces_atomic(
922 sc
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
923 ath9k_vif_iter
, iter_data
);
926 /* Called with sc->mutex held. */
927 static void ath9k_calculate_summary_state(struct ieee80211_hw
*hw
,
928 struct ieee80211_vif
*vif
)
930 struct ath_softc
*sc
= hw
->priv
;
931 struct ath_hw
*ah
= sc
->sc_ah
;
932 struct ath_common
*common
= ath9k_hw_common(ah
);
933 struct ath9k_vif_iter_data iter_data
;
934 enum nl80211_iftype old_opmode
= ah
->opmode
;
936 ath9k_calculate_iter_data(hw
, vif
, &iter_data
);
938 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
939 ath_hw_setbssidmask(common
);
941 if (iter_data
.naps
> 0) {
942 ath9k_hw_set_tsfadjust(ah
, true);
943 ah
->opmode
= NL80211_IFTYPE_AP
;
945 ath9k_hw_set_tsfadjust(ah
, false);
947 if (iter_data
.nmeshes
)
948 ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
949 else if (iter_data
.nwds
)
950 ah
->opmode
= NL80211_IFTYPE_AP
;
951 else if (iter_data
.nadhocs
)
952 ah
->opmode
= NL80211_IFTYPE_ADHOC
;
954 ah
->opmode
= NL80211_IFTYPE_STATION
;
957 ath9k_hw_setopmode(ah
);
959 if ((iter_data
.nstations
+ iter_data
.nadhocs
+ iter_data
.nmeshes
) > 0)
960 ah
->imask
|= ATH9K_INT_TSFOOR
;
962 ah
->imask
&= ~ATH9K_INT_TSFOOR
;
964 ath9k_hw_set_interrupts(ah
);
967 * If we are changing the opmode to STATION,
968 * a beacon sync needs to be done.
970 if (ah
->opmode
== NL80211_IFTYPE_STATION
&&
971 old_opmode
== NL80211_IFTYPE_AP
&&
972 test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
)) {
973 ieee80211_iterate_active_interfaces_atomic(
974 sc
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
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
>= IEEE80211_NUM_ACS
)
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 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
))
1454 ath9k_mci_update_wlan_channels(sc
, false);
1456 ath_dbg(common
, CONFIG
,
1457 "Primary Station interface: %pM, BSSID: %pM\n",
1458 vif
->addr
, common
->curbssid
);
1461 static void ath9k_bss_assoc_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1463 struct ath_softc
*sc
= data
;
1464 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1466 if (test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
))
1469 if (bss_conf
->assoc
)
1470 ath9k_set_assoc_state(sc
, vif
);
1473 static void ath9k_bss_info_changed(struct ieee80211_hw
*hw
,
1474 struct ieee80211_vif
*vif
,
1475 struct ieee80211_bss_conf
*bss_conf
,
1479 (BSS_CHANGED_ASSOC | \
1480 BSS_CHANGED_IBSS | \
1481 BSS_CHANGED_BEACON_ENABLED)
1483 struct ath_softc
*sc
= hw
->priv
;
1484 struct ath_hw
*ah
= sc
->sc_ah
;
1485 struct ath_common
*common
= ath9k_hw_common(ah
);
1486 struct ath_vif
*avp
= (void *)vif
->drv_priv
;
1489 ath9k_ps_wakeup(sc
);
1490 mutex_lock(&sc
->mutex
);
1492 if (changed
& BSS_CHANGED_ASSOC
) {
1493 ath_dbg(common
, CONFIG
, "BSSID %pM Changed ASSOC %d\n",
1494 bss_conf
->bssid
, bss_conf
->assoc
);
1496 if (avp
->primary_sta_vif
&& !bss_conf
->assoc
) {
1497 clear_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
);
1498 avp
->primary_sta_vif
= false;
1500 if (ah
->opmode
== NL80211_IFTYPE_STATION
)
1501 clear_bit(SC_OP_BEACONS
, &sc
->sc_flags
);
1504 ieee80211_iterate_active_interfaces_atomic(
1505 sc
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1506 ath9k_bss_assoc_iter
, sc
);
1508 if (!test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
) &&
1509 ah
->opmode
== NL80211_IFTYPE_STATION
) {
1510 memset(common
->curbssid
, 0, ETH_ALEN
);
1512 ath9k_hw_write_associd(sc
->sc_ah
);
1513 if (ath9k_hw_mci_is_enabled(sc
->sc_ah
))
1514 ath9k_mci_update_wlan_channels(sc
, true);
1518 if (changed
& BSS_CHANGED_IBSS
) {
1519 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1520 common
->curaid
= bss_conf
->aid
;
1521 ath9k_hw_write_associd(sc
->sc_ah
);
1524 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) ||
1525 (changed
& BSS_CHANGED_BEACON_INT
)) {
1526 if (ah
->opmode
== NL80211_IFTYPE_AP
&&
1527 bss_conf
->enable_beacon
)
1528 ath9k_set_tsfadjust(sc
, vif
);
1529 if (ath9k_allow_beacon_config(sc
, vif
))
1530 ath9k_beacon_config(sc
, vif
, changed
);
1533 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1534 if (bss_conf
->use_short_slot
)
1538 if (vif
->type
== NL80211_IFTYPE_AP
) {
1540 * Defer update, so that connected stations can adjust
1541 * their settings at the same time.
1542 * See beacon.c for more details
1544 sc
->beacon
.slottime
= slottime
;
1545 sc
->beacon
.updateslot
= UPDATE
;
1547 ah
->slottime
= slottime
;
1548 ath9k_hw_init_global_settings(ah
);
1552 if (changed
& CHECK_ANI
)
1555 mutex_unlock(&sc
->mutex
);
1556 ath9k_ps_restore(sc
);
1561 static u64
ath9k_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1563 struct ath_softc
*sc
= hw
->priv
;
1566 mutex_lock(&sc
->mutex
);
1567 ath9k_ps_wakeup(sc
);
1568 tsf
= ath9k_hw_gettsf64(sc
->sc_ah
);
1569 ath9k_ps_restore(sc
);
1570 mutex_unlock(&sc
->mutex
);
1575 static void ath9k_set_tsf(struct ieee80211_hw
*hw
,
1576 struct ieee80211_vif
*vif
,
1579 struct ath_softc
*sc
= hw
->priv
;
1581 mutex_lock(&sc
->mutex
);
1582 ath9k_ps_wakeup(sc
);
1583 ath9k_hw_settsf64(sc
->sc_ah
, tsf
);
1584 ath9k_ps_restore(sc
);
1585 mutex_unlock(&sc
->mutex
);
1588 static void ath9k_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1590 struct ath_softc
*sc
= hw
->priv
;
1592 mutex_lock(&sc
->mutex
);
1594 ath9k_ps_wakeup(sc
);
1595 ath9k_hw_reset_tsf(sc
->sc_ah
);
1596 ath9k_ps_restore(sc
);
1598 mutex_unlock(&sc
->mutex
);
1601 static int ath9k_ampdu_action(struct ieee80211_hw
*hw
,
1602 struct ieee80211_vif
*vif
,
1603 enum ieee80211_ampdu_mlme_action action
,
1604 struct ieee80211_sta
*sta
,
1605 u16 tid
, u16
*ssn
, u8 buf_size
)
1607 struct ath_softc
*sc
= hw
->priv
;
1613 case IEEE80211_AMPDU_RX_START
:
1615 case IEEE80211_AMPDU_RX_STOP
:
1617 case IEEE80211_AMPDU_TX_START
:
1618 ath9k_ps_wakeup(sc
);
1619 ret
= ath_tx_aggr_start(sc
, sta
, tid
, ssn
);
1621 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1622 ath9k_ps_restore(sc
);
1624 case IEEE80211_AMPDU_TX_STOP
:
1625 ath9k_ps_wakeup(sc
);
1626 ath_tx_aggr_stop(sc
, sta
, tid
);
1627 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1628 ath9k_ps_restore(sc
);
1630 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1631 ath9k_ps_wakeup(sc
);
1632 ath_tx_aggr_resume(sc
, sta
, tid
);
1633 ath9k_ps_restore(sc
);
1636 ath_err(ath9k_hw_common(sc
->sc_ah
), "Unknown AMPDU action\n");
1644 static int ath9k_get_survey(struct ieee80211_hw
*hw
, int idx
,
1645 struct survey_info
*survey
)
1647 struct ath_softc
*sc
= hw
->priv
;
1648 struct ath_common
*common
= ath9k_hw_common(sc
->sc_ah
);
1649 struct ieee80211_supported_band
*sband
;
1650 struct ieee80211_channel
*chan
;
1651 unsigned long flags
;
1654 spin_lock_irqsave(&common
->cc_lock
, flags
);
1656 ath_update_survey_stats(sc
);
1658 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
1659 if (sband
&& idx
>= sband
->n_channels
) {
1660 idx
-= sband
->n_channels
;
1665 sband
= hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
];
1667 if (!sband
|| idx
>= sband
->n_channels
) {
1668 spin_unlock_irqrestore(&common
->cc_lock
, flags
);
1672 chan
= &sband
->channels
[idx
];
1673 pos
= chan
->hw_value
;
1674 memcpy(survey
, &sc
->survey
[pos
], sizeof(*survey
));
1675 survey
->channel
= chan
;
1676 spin_unlock_irqrestore(&common
->cc_lock
, flags
);
1681 static void ath9k_set_coverage_class(struct ieee80211_hw
*hw
, u8 coverage_class
)
1683 struct ath_softc
*sc
= hw
->priv
;
1684 struct ath_hw
*ah
= sc
->sc_ah
;
1686 mutex_lock(&sc
->mutex
);
1687 ah
->coverage_class
= coverage_class
;
1689 ath9k_ps_wakeup(sc
);
1690 ath9k_hw_init_global_settings(ah
);
1691 ath9k_ps_restore(sc
);
1693 mutex_unlock(&sc
->mutex
);
1696 static void ath9k_flush(struct ieee80211_hw
*hw
, bool drop
)
1698 struct ath_softc
*sc
= hw
->priv
;
1699 struct ath_hw
*ah
= sc
->sc_ah
;
1700 struct ath_common
*common
= ath9k_hw_common(ah
);
1701 int timeout
= 200; /* ms */
1705 mutex_lock(&sc
->mutex
);
1706 cancel_delayed_work_sync(&sc
->tx_complete_work
);
1708 if (ah
->ah_flags
& AH_UNPLUGGED
) {
1709 ath_dbg(common
, ANY
, "Device has been unplugged!\n");
1710 mutex_unlock(&sc
->mutex
);
1714 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
1715 ath_dbg(common
, ANY
, "Device not present\n");
1716 mutex_unlock(&sc
->mutex
);
1720 for (j
= 0; j
< timeout
; j
++) {
1724 usleep_range(1000, 2000);
1726 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1727 if (!ATH_TXQ_SETUP(sc
, i
))
1730 npend
= ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]);
1741 ath9k_ps_wakeup(sc
);
1742 spin_lock_bh(&sc
->sc_pcu_lock
);
1743 drain_txq
= ath_drain_all_txq(sc
, false);
1744 spin_unlock_bh(&sc
->sc_pcu_lock
);
1747 ath_reset(sc
, false);
1749 ath9k_ps_restore(sc
);
1750 ieee80211_wake_queues(hw
);
1753 ieee80211_queue_delayed_work(hw
, &sc
->tx_complete_work
, 0);
1754 mutex_unlock(&sc
->mutex
);
1757 static bool ath9k_tx_frames_pending(struct ieee80211_hw
*hw
)
1759 struct ath_softc
*sc
= hw
->priv
;
1762 for (i
= 0; i
< ATH9K_NUM_TX_QUEUES
; i
++) {
1763 if (!ATH_TXQ_SETUP(sc
, i
))
1766 if (ath9k_has_pending_frames(sc
, &sc
->tx
.txq
[i
]))
1772 static int ath9k_tx_last_beacon(struct ieee80211_hw
*hw
)
1774 struct ath_softc
*sc
= hw
->priv
;
1775 struct ath_hw
*ah
= sc
->sc_ah
;
1776 struct ieee80211_vif
*vif
;
1777 struct ath_vif
*avp
;
1779 struct ath_tx_status ts
;
1780 bool edma
= !!(ah
->caps
.hw_caps
& ATH9K_HW_CAP_EDMA
);
1783 vif
= sc
->beacon
.bslot
[0];
1787 if (!vif
->bss_conf
.enable_beacon
)
1790 avp
= (void *)vif
->drv_priv
;
1792 if (!sc
->beacon
.tx_processed
&& !edma
) {
1793 tasklet_disable(&sc
->bcon_tasklet
);
1796 if (!bf
|| !bf
->bf_mpdu
)
1799 status
= ath9k_hw_txprocdesc(ah
, bf
->bf_desc
, &ts
);
1800 if (status
== -EINPROGRESS
)
1803 sc
->beacon
.tx_processed
= true;
1804 sc
->beacon
.tx_last
= !(ts
.ts_status
& ATH9K_TXERR_MASK
);
1807 tasklet_enable(&sc
->bcon_tasklet
);
1810 return sc
->beacon
.tx_last
;
1813 static int ath9k_get_stats(struct ieee80211_hw
*hw
,
1814 struct ieee80211_low_level_stats
*stats
)
1816 struct ath_softc
*sc
= hw
->priv
;
1817 struct ath_hw
*ah
= sc
->sc_ah
;
1818 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1820 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1821 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1822 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1823 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1827 static u32
fill_chainmask(u32 cap
, u32
new)
1832 for (i
= 0; cap
&& new; i
++, cap
>>= 1) {
1833 if (!(cap
& BIT(0)))
1845 static bool validate_antenna_mask(struct ath_hw
*ah
, u32 val
)
1847 switch (val
& 0x7) {
1853 return (ah
->caps
.rx_chainmask
== 1);
1859 static int ath9k_set_antenna(struct ieee80211_hw
*hw
, u32 tx_ant
, u32 rx_ant
)
1861 struct ath_softc
*sc
= hw
->priv
;
1862 struct ath_hw
*ah
= sc
->sc_ah
;
1864 if (ah
->caps
.rx_chainmask
!= 1)
1867 if (!validate_antenna_mask(ah
, rx_ant
) || !tx_ant
)
1870 sc
->ant_rx
= rx_ant
;
1871 sc
->ant_tx
= tx_ant
;
1873 if (ah
->caps
.rx_chainmask
== 1)
1876 /* AR9100 runs into calibration issues if not all rx chains are enabled */
1877 if (AR_SREV_9100(ah
))
1878 ah
->rxchainmask
= 0x7;
1880 ah
->rxchainmask
= fill_chainmask(ah
->caps
.rx_chainmask
, rx_ant
);
1882 ah
->txchainmask
= fill_chainmask(ah
->caps
.tx_chainmask
, tx_ant
);
1883 ath9k_reload_chainmask_settings(sc
);
1888 static int ath9k_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
1890 struct ath_softc
*sc
= hw
->priv
;
1892 *tx_ant
= sc
->ant_tx
;
1893 *rx_ant
= sc
->ant_rx
;
1897 #ifdef CONFIG_ATH9K_DEBUGFS
1899 /* Ethtool support for get-stats */
1901 #define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1902 static const char ath9k_gstrings_stats
[][ETH_GSTRING_LEN
] = {
1909 AMKSTR(d_tx_mpdus_queued
),
1910 AMKSTR(d_tx_mpdus_completed
),
1911 AMKSTR(d_tx_mpdu_xretries
),
1912 AMKSTR(d_tx_aggregates
),
1913 AMKSTR(d_tx_ampdus_queued_hw
),
1914 AMKSTR(d_tx_ampdus_queued_sw
),
1915 AMKSTR(d_tx_ampdus_completed
),
1916 AMKSTR(d_tx_ampdu_retries
),
1917 AMKSTR(d_tx_ampdu_xretries
),
1918 AMKSTR(d_tx_fifo_underrun
),
1919 AMKSTR(d_tx_op_exceeded
),
1920 AMKSTR(d_tx_timer_expiry
),
1921 AMKSTR(d_tx_desc_cfg_err
),
1922 AMKSTR(d_tx_data_underrun
),
1923 AMKSTR(d_tx_delim_underrun
),
1925 "d_rx_decrypt_crc_err",
1928 "d_rx_pre_delim_crc_err",
1929 "d_rx_post_delim_crc_err",
1930 "d_rx_decrypt_busy_err",
1932 "d_rx_phyerr_radar",
1933 "d_rx_phyerr_ofdm_timing",
1934 "d_rx_phyerr_cck_timing",
1937 #define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
1939 static void ath9k_get_et_strings(struct ieee80211_hw
*hw
,
1940 struct ieee80211_vif
*vif
,
1943 if (sset
== ETH_SS_STATS
)
1944 memcpy(data
, *ath9k_gstrings_stats
,
1945 sizeof(ath9k_gstrings_stats
));
1948 static int ath9k_get_et_sset_count(struct ieee80211_hw
*hw
,
1949 struct ieee80211_vif
*vif
, int sset
)
1951 if (sset
== ETH_SS_STATS
)
1952 return ATH9K_SSTATS_LEN
;
1956 #define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
1957 #define AWDATA(elem) \
1959 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BE)].elem; \
1960 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_BK)].elem; \
1961 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VI)].elem; \
1962 data[i++] = sc->debug.stats.txstats[PR_QNUM(IEEE80211_AC_VO)].elem; \
1965 #define AWDATA_RX(elem) \
1967 data[i++] = sc->debug.stats.rxstats.elem; \
1970 static void ath9k_get_et_stats(struct ieee80211_hw
*hw
,
1971 struct ieee80211_vif
*vif
,
1972 struct ethtool_stats
*stats
, u64
*data
)
1974 struct ath_softc
*sc
= hw
->priv
;
1977 data
[i
++] = (sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_BE
)].tx_pkts_all
+
1978 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_BK
)].tx_pkts_all
+
1979 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_VI
)].tx_pkts_all
+
1980 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_VO
)].tx_pkts_all
);
1981 data
[i
++] = (sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_BE
)].tx_bytes_all
+
1982 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_BK
)].tx_bytes_all
+
1983 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_VI
)].tx_bytes_all
+
1984 sc
->debug
.stats
.txstats
[PR_QNUM(IEEE80211_AC_VO
)].tx_bytes_all
);
1985 AWDATA_RX(rx_pkts_all
);
1986 AWDATA_RX(rx_bytes_all
);
1988 AWDATA(tx_pkts_all
);
1989 AWDATA(tx_bytes_all
);
1994 AWDATA(a_queued_hw
);
1995 AWDATA(a_queued_sw
);
1996 AWDATA(a_completed
);
1999 AWDATA(fifo_underrun
);
2002 AWDATA(desc_cfg_err
);
2003 AWDATA(data_underrun
);
2004 AWDATA(delim_underrun
);
2006 AWDATA_RX(decrypt_crc_err
);
2009 AWDATA_RX(pre_delim_crc_err
);
2010 AWDATA_RX(post_delim_crc_err
);
2011 AWDATA_RX(decrypt_busy_err
);
2013 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_RADAR
]);
2014 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_OFDM_TIMING
]);
2015 AWDATA_RX(phy_err_stats
[ATH9K_PHYERR_CCK_TIMING
]);
2017 WARN_ON(i
!= ATH9K_SSTATS_LEN
);
2020 /* End of ethtool get-stats functions */
2025 #ifdef CONFIG_PM_SLEEP
2027 static void ath9k_wow_map_triggers(struct ath_softc
*sc
,
2028 struct cfg80211_wowlan
*wowlan
,
2031 if (wowlan
->disconnect
)
2032 *wow_triggers
|= AH_WOW_LINK_CHANGE
|
2034 if (wowlan
->magic_pkt
)
2035 *wow_triggers
|= AH_WOW_MAGIC_PATTERN_EN
;
2037 if (wowlan
->n_patterns
)
2038 *wow_triggers
|= AH_WOW_USER_PATTERN_EN
;
2040 sc
->wow_enabled
= *wow_triggers
;
2044 static void ath9k_wow_add_disassoc_deauth_pattern(struct ath_softc
*sc
)
2046 struct ath_hw
*ah
= sc
->sc_ah
;
2047 struct ath_common
*common
= ath9k_hw_common(ah
);
2048 struct ath9k_hw_capabilities
*pcaps
= &ah
->caps
;
2049 int pattern_count
= 0;
2051 u8 dis_deauth_pattern
[MAX_PATTERN_SIZE
];
2052 u8 dis_deauth_mask
[MAX_PATTERN_SIZE
];
2054 memset(dis_deauth_pattern
, 0, MAX_PATTERN_SIZE
);
2055 memset(dis_deauth_mask
, 0, MAX_PATTERN_SIZE
);
2058 * Create Dissassociate / Deauthenticate packet filter
2060 * 2 bytes 2 byte 6 bytes 6 bytes 6 bytes
2061 * +--------------+----------+---------+--------+--------+----
2062 * + Frame Control+ Duration + DA + SA + BSSID +
2063 * +--------------+----------+---------+--------+--------+----
2065 * The above is the management frame format for disassociate/
2066 * deauthenticate pattern, from this we need to match the first byte
2067 * of 'Frame Control' and DA, SA, and BSSID fields
2068 * (skipping 2nd byte of FC and Duration feild.
2070 * Disassociate pattern
2071 * --------------------
2072 * Frame control = 00 00 1010
2073 * DA, SA, BSSID = x:x:x:x:x:x
2074 * Pattern will be A0000000 | x:x:x:x:x:x | x:x:x:x:x:x
2075 * | x:x:x:x:x:x -- 22 bytes
2077 * Deauthenticate pattern
2078 * ----------------------
2079 * Frame control = 00 00 1100
2080 * DA, SA, BSSID = x:x:x:x:x:x
2081 * Pattern will be C0000000 | x:x:x:x:x:x | x:x:x:x:x:x
2082 * | x:x:x:x:x:x -- 22 bytes
2085 /* Create Disassociate Pattern first */
2089 /* Fill out the mask with all FF's */
2091 for (i
= 0; i
< MAX_PATTERN_MASK_SIZE
; i
++)
2092 dis_deauth_mask
[i
] = 0xff;
2094 /* copy the first byte of frame control field */
2095 dis_deauth_pattern
[byte_cnt
] = 0xa0;
2098 /* skip 2nd byte of frame control and Duration field */
2102 * need not match the destination mac address, it can be a broadcast
2103 * mac address or an unicast to this station
2107 /* copy the source mac address */
2108 memcpy((dis_deauth_pattern
+ byte_cnt
), common
->curbssid
, ETH_ALEN
);
2112 /* copy the bssid, its same as the source mac address */
2114 memcpy((dis_deauth_pattern
+ byte_cnt
), common
->curbssid
, ETH_ALEN
);
2116 /* Create Disassociate pattern mask */
2118 if (pcaps
->hw_caps
& ATH9K_HW_WOW_PATTERN_MATCH_EXACT
) {
2120 if (pcaps
->hw_caps
& ATH9K_HW_WOW_PATTERN_MATCH_DWORD
) {
2122 * for AR9280, because of hardware limitation, the
2123 * first 4 bytes have to be matched for all patterns.
2124 * the mask for disassociation and de-auth pattern
2125 * matching need to enable the first 4 bytes.
2126 * also the duration field needs to be filled.
2128 dis_deauth_mask
[0] = 0xf0;
2131 * fill in duration field
2132 FIXME: what is the exact value ?
2134 dis_deauth_pattern
[2] = 0xff;
2135 dis_deauth_pattern
[3] = 0xff;
2137 dis_deauth_mask
[0] = 0xfe;
2140 dis_deauth_mask
[1] = 0x03;
2141 dis_deauth_mask
[2] = 0xc0;
2143 dis_deauth_mask
[0] = 0xef;
2144 dis_deauth_mask
[1] = 0x3f;
2145 dis_deauth_mask
[2] = 0x00;
2146 dis_deauth_mask
[3] = 0xfc;
2149 ath_dbg(common
, WOW
, "Adding disassoc/deauth patterns for WoW\n");
2151 ath9k_hw_wow_apply_pattern(ah
, dis_deauth_pattern
, dis_deauth_mask
,
2152 pattern_count
, byte_cnt
);
2156 * for de-authenticate pattern, only the first byte of the frame
2157 * control field gets changed from 0xA0 to 0xC0
2159 dis_deauth_pattern
[0] = 0xC0;
2161 ath9k_hw_wow_apply_pattern(ah
, dis_deauth_pattern
, dis_deauth_mask
,
2162 pattern_count
, byte_cnt
);
2166 static void ath9k_wow_add_pattern(struct ath_softc
*sc
,
2167 struct cfg80211_wowlan
*wowlan
)
2169 struct ath_hw
*ah
= sc
->sc_ah
;
2170 struct ath9k_wow_pattern
*wow_pattern
= NULL
;
2171 struct cfg80211_wowlan_trig_pkt_pattern
*patterns
= wowlan
->patterns
;
2175 if (!wowlan
->n_patterns
)
2179 * Add the new user configured patterns
2181 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
2183 wow_pattern
= kzalloc(sizeof(*wow_pattern
), GFP_KERNEL
);
2189 * TODO: convert the generic user space pattern to
2190 * appropriate chip specific/802.11 pattern.
2193 mask_len
= DIV_ROUND_UP(wowlan
->patterns
[i
].pattern_len
, 8);
2194 memset(wow_pattern
->pattern_bytes
, 0, MAX_PATTERN_SIZE
);
2195 memset(wow_pattern
->mask_bytes
, 0, MAX_PATTERN_SIZE
);
2196 memcpy(wow_pattern
->pattern_bytes
, patterns
[i
].pattern
,
2197 patterns
[i
].pattern_len
);
2198 memcpy(wow_pattern
->mask_bytes
, patterns
[i
].mask
, mask_len
);
2199 wow_pattern
->pattern_len
= patterns
[i
].pattern_len
;
2202 * just need to take care of deauth and disssoc pattern,
2203 * make sure we don't overwrite them.
2206 ath9k_hw_wow_apply_pattern(ah
, wow_pattern
->pattern_bytes
,
2207 wow_pattern
->mask_bytes
,
2209 wow_pattern
->pattern_len
);
2216 static int ath9k_suspend(struct ieee80211_hw
*hw
,
2217 struct cfg80211_wowlan
*wowlan
)
2219 struct ath_softc
*sc
= hw
->priv
;
2220 struct ath_hw
*ah
= sc
->sc_ah
;
2221 struct ath_common
*common
= ath9k_hw_common(ah
);
2222 u32 wow_triggers_enabled
= 0;
2225 mutex_lock(&sc
->mutex
);
2227 ath_cancel_work(sc
);
2229 del_timer_sync(&sc
->rx_poll_timer
);
2231 if (test_bit(SC_OP_INVALID
, &sc
->sc_flags
)) {
2232 ath_dbg(common
, ANY
, "Device not present\n");
2237 if (WARN_ON(!wowlan
)) {
2238 ath_dbg(common
, WOW
, "None of the WoW triggers enabled\n");
2243 if (!device_can_wakeup(sc
->dev
)) {
2244 ath_dbg(common
, WOW
, "device_can_wakeup failed, WoW is not enabled\n");
2250 * none of the sta vifs are associated
2251 * and we are not currently handling multivif
2252 * cases, for instance we have to seperately
2253 * configure 'keep alive frame' for each
2257 if (!test_bit(SC_OP_PRIM_STA_VIF
, &sc
->sc_flags
)) {
2258 ath_dbg(common
, WOW
, "None of the STA vifs are associated\n");
2263 if (sc
->nvifs
> 1) {
2264 ath_dbg(common
, WOW
, "WoW for multivif is not yet supported\n");
2269 ath9k_wow_map_triggers(sc
, wowlan
, &wow_triggers_enabled
);
2271 ath_dbg(common
, WOW
, "WoW triggers enabled 0x%x\n",
2272 wow_triggers_enabled
);
2274 ath9k_ps_wakeup(sc
);
2276 ath9k_stop_btcoex(sc
);
2279 * Enable wake up on recieving disassoc/deauth
2282 ath9k_wow_add_disassoc_deauth_pattern(sc
);
2284 if (wow_triggers_enabled
& AH_WOW_USER_PATTERN_EN
)
2285 ath9k_wow_add_pattern(sc
, wowlan
);
2287 spin_lock_bh(&sc
->sc_pcu_lock
);
2289 * To avoid false wake, we enable beacon miss interrupt only
2290 * when we go to sleep. We save the current interrupt mask
2291 * so we can restore it after the system wakes up
2293 sc
->wow_intr_before_sleep
= ah
->imask
;
2294 ah
->imask
&= ~ATH9K_INT_GLOBAL
;
2295 ath9k_hw_disable_interrupts(ah
);
2296 ah
->imask
= ATH9K_INT_BMISS
| ATH9K_INT_GLOBAL
;
2297 ath9k_hw_set_interrupts(ah
);
2298 ath9k_hw_enable_interrupts(ah
);
2300 spin_unlock_bh(&sc
->sc_pcu_lock
);
2303 * we can now sync irq and kill any running tasklets, since we already
2304 * disabled interrupts and not holding a spin lock
2306 synchronize_irq(sc
->irq
);
2307 tasklet_kill(&sc
->intr_tq
);
2309 ath9k_hw_wow_enable(ah
, wow_triggers_enabled
);
2311 ath9k_ps_restore(sc
);
2312 ath_dbg(common
, ANY
, "WoW enabled in ath9k\n");
2313 atomic_inc(&sc
->wow_sleep_proc_intr
);
2316 mutex_unlock(&sc
->mutex
);
2320 static int ath9k_resume(struct ieee80211_hw
*hw
)
2322 struct ath_softc
*sc
= hw
->priv
;
2323 struct ath_hw
*ah
= sc
->sc_ah
;
2324 struct ath_common
*common
= ath9k_hw_common(ah
);
2327 mutex_lock(&sc
->mutex
);
2329 ath9k_ps_wakeup(sc
);
2331 spin_lock_bh(&sc
->sc_pcu_lock
);
2333 ath9k_hw_disable_interrupts(ah
);
2334 ah
->imask
= sc
->wow_intr_before_sleep
;
2335 ath9k_hw_set_interrupts(ah
);
2336 ath9k_hw_enable_interrupts(ah
);
2338 spin_unlock_bh(&sc
->sc_pcu_lock
);
2340 wow_status
= ath9k_hw_wow_wakeup(ah
);
2342 if (atomic_read(&sc
->wow_got_bmiss_intr
) == 0) {
2344 * some devices may not pick beacon miss
2345 * as the reason they woke up so we add
2346 * that here for that shortcoming.
2348 wow_status
|= AH_WOW_BEACON_MISS
;
2349 atomic_dec(&sc
->wow_got_bmiss_intr
);
2350 ath_dbg(common
, ANY
, "Beacon miss interrupt picked up during WoW sleep\n");
2353 atomic_dec(&sc
->wow_sleep_proc_intr
);
2356 ath_dbg(common
, ANY
, "Waking up due to WoW triggers %s with WoW status = %x\n",
2357 ath9k_hw_wow_event_to_string(wow_status
), wow_status
);
2360 ath_restart_work(sc
);
2361 ath9k_start_btcoex(sc
);
2363 ath9k_ps_restore(sc
);
2364 mutex_unlock(&sc
->mutex
);
2369 static void ath9k_set_wakeup(struct ieee80211_hw
*hw
, bool enabled
)
2371 struct ath_softc
*sc
= hw
->priv
;
2373 mutex_lock(&sc
->mutex
);
2374 device_init_wakeup(sc
->dev
, 1);
2375 device_set_wakeup_enable(sc
->dev
, enabled
);
2376 mutex_unlock(&sc
->mutex
);
2381 struct ieee80211_ops ath9k_ops
= {
2383 .start
= ath9k_start
,
2385 .add_interface
= ath9k_add_interface
,
2386 .change_interface
= ath9k_change_interface
,
2387 .remove_interface
= ath9k_remove_interface
,
2388 .config
= ath9k_config
,
2389 .configure_filter
= ath9k_configure_filter
,
2390 .sta_add
= ath9k_sta_add
,
2391 .sta_remove
= ath9k_sta_remove
,
2392 .sta_notify
= ath9k_sta_notify
,
2393 .conf_tx
= ath9k_conf_tx
,
2394 .bss_info_changed
= ath9k_bss_info_changed
,
2395 .set_key
= ath9k_set_key
,
2396 .get_tsf
= ath9k_get_tsf
,
2397 .set_tsf
= ath9k_set_tsf
,
2398 .reset_tsf
= ath9k_reset_tsf
,
2399 .ampdu_action
= ath9k_ampdu_action
,
2400 .get_survey
= ath9k_get_survey
,
2401 .rfkill_poll
= ath9k_rfkill_poll_state
,
2402 .set_coverage_class
= ath9k_set_coverage_class
,
2403 .flush
= ath9k_flush
,
2404 .tx_frames_pending
= ath9k_tx_frames_pending
,
2405 .tx_last_beacon
= ath9k_tx_last_beacon
,
2406 .get_stats
= ath9k_get_stats
,
2407 .set_antenna
= ath9k_set_antenna
,
2408 .get_antenna
= ath9k_get_antenna
,
2410 #ifdef CONFIG_PM_SLEEP
2411 .suspend
= ath9k_suspend
,
2412 .resume
= ath9k_resume
,
2413 .set_wakeup
= ath9k_set_wakeup
,
2416 #ifdef CONFIG_ATH9K_DEBUGFS
2417 .get_et_sset_count
= ath9k_get_et_sset_count
,
2418 .get_et_stats
= ath9k_get_et_stats
,
2419 .get_et_strings
= ath9k_get_et_strings
,