Lines Matching refs:sc

23 static int ath_set_channel(struct ath_softc *sc)  in ath_set_channel()  argument
25 struct ath_hw *ah = sc->sc_ah; in ath_set_channel()
27 struct ieee80211_hw *hw = sc->hw; in ath_set_channel()
29 struct cfg80211_chan_def *chandef = &sc->cur_chan->chandef; in ath_set_channel()
47 ath_update_survey_stats(sc); in ath_set_channel()
57 if (!sc->cur_chan->offchannel && sc->cur_survey != &sc->survey[pos]) { in ath_set_channel()
58 if (sc->cur_survey) in ath_set_channel()
59 sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; in ath_set_channel()
61 sc->cur_survey = &sc->survey[pos]; in ath_set_channel()
63 memset(sc->cur_survey, 0, sizeof(struct survey_info)); in ath_set_channel()
64 sc->cur_survey->filled |= SURVEY_INFO_IN_USE; in ath_set_channel()
65 } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) { in ath_set_channel()
66 memset(&sc->survey[pos], 0, sizeof(struct survey_info)); in ath_set_channel()
69 hchan = &sc->sc_ah->channels[pos]; in ath_set_channel()
70 r = ath_reset(sc, hchan); in ath_set_channel()
79 ath_update_survey_nf(sc, old_pos); in ath_set_channel()
96 sc->spec_priv.spectral_mode == SPECTRAL_CHANSCAN) in ath_set_channel()
97 ath9k_cmn_spectral_scan_trigger(common, &sc->spec_priv); in ath_set_channel()
103 void ath_chanctx_init(struct ath_softc *sc) in ath_chanctx_init() argument
106 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_init()
117 ctx = &sc->chanctx[i]; in ath_chanctx_init()
130 void ath_chanctx_set_channel(struct ath_softc *sc, struct ath_chanctx *ctx, in ath_chanctx_set_channel() argument
133 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_set_channel()
136 spin_lock_bh(&sc->chan_lock); in ath_chanctx_set_channel()
139 cur_chan = sc->cur_chan == ctx; in ath_chanctx_set_channel()
140 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_set_channel()
148 ath_set_channel(sc); in ath_chanctx_set_channel()
157 struct ath_chanctx* ath_is_go_chanctx_present(struct ath_softc *sc) in ath_is_go_chanctx_present() argument
163 spin_lock_bh(&sc->chan_lock); in ath_is_go_chanctx_present()
165 ath_for_each_chanctx(sc, ctx) { in ath_is_go_chanctx_present()
173 spin_unlock_bh(&sc->chan_lock); in ath_is_go_chanctx_present()
179 spin_unlock_bh(&sc->chan_lock); in ath_is_go_chanctx_present()
233 static u32 chanctx_event_delta(struct ath_softc *sc) in chanctx_event_delta() argument
239 old = &sc->last_event_time; in chanctx_event_delta()
242 sc->last_event_time = ts; in chanctx_event_delta()
247 void ath_chanctx_check_active(struct ath_softc *sc, struct ath_chanctx *ctx) in ath_chanctx_check_active() argument
249 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_check_active()
258 if (ctx == &sc->offchannel.chan) { in ath_chanctx_check_active()
259 spin_lock_bh(&sc->chan_lock); in ath_chanctx_check_active()
261 if (likely(sc->sched.channel_switch_time)) in ath_chanctx_check_active()
263 usecs_to_jiffies(sc->sched.channel_switch_time); in ath_chanctx_check_active()
268 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_check_active()
296 ath_for_each_chanctx(sc, ctx) { in ath_chanctx_check_active()
302 spin_lock_bh(&sc->chan_lock); in ath_chanctx_check_active()
307 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_check_active()
311 ictx->flush_timeout = usecs_to_jiffies(sc->sched.channel_switch_time); in ath_chanctx_check_active()
314 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_check_active()
318 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_check_active()
321 ath_chanctx_event(sc, NULL, in ath_chanctx_check_active()
327 ath_chanctx_get_next(struct ath_softc *sc, struct ath_chanctx *ctx) in ath_chanctx_get_next() argument
329 int idx = ctx - &sc->chanctx[0]; in ath_chanctx_get_next()
331 return &sc->chanctx[!idx]; in ath_chanctx_get_next()
334 static void ath_chanctx_adjust_tbtt_delta(struct ath_softc *sc) in ath_chanctx_adjust_tbtt_delta() argument
341 beacon_int = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval); in ath_chanctx_adjust_tbtt_delta()
343 cur = sc->cur_chan; in ath_chanctx_adjust_tbtt_delta()
344 prev = ath_chanctx_get_next(sc, cur); in ath_chanctx_adjust_tbtt_delta()
373 static void ath_chanctx_setup_timer(struct ath_softc *sc, u32 tsf_time) in ath_chanctx_setup_timer() argument
375 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_setup_timer()
376 struct ath_hw *ah = sc->sc_ah; in ath_chanctx_setup_timer()
379 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, tsf_time, 1000000); in ath_chanctx_setup_timer()
382 mod_timer(&sc->sched.timer, jiffies + timeout); in ath_chanctx_setup_timer()
389 static void ath_chanctx_handle_bmiss(struct ath_softc *sc, in ath_chanctx_handle_bmiss() argument
399 if (ctx->active && sc->sched.extend_absence) { in ath_chanctx_handle_bmiss()
401 sc->sched.extend_absence = false; in ath_chanctx_handle_bmiss()
408 if (ctx->active && sc->sched.beacon_miss >= 2) { in ath_chanctx_handle_bmiss()
410 sc->sched.extend_absence = true; in ath_chanctx_handle_bmiss()
414 static void ath_chanctx_offchannel_noa(struct ath_softc *sc, in ath_chanctx_offchannel_noa() argument
419 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_offchannel_noa()
423 avp->offchannel_duration = sc->sched.offchannel_duration; in ath_chanctx_offchannel_noa()
440 static void ath_chanctx_set_periodic_noa(struct ath_softc *sc, in ath_chanctx_set_periodic_noa() argument
446 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_set_periodic_noa()
451 if (sc->sched.extend_absence) in ath_chanctx_set_periodic_noa()
453 sc->sched.channel_switch_time; in ath_chanctx_set_periodic_noa()
457 sc->sched.channel_switch_time; in ath_chanctx_set_periodic_noa()
460 sc->sched.extend_absence) in ath_chanctx_set_periodic_noa()
473 static void ath_chanctx_set_oneshot_noa(struct ath_softc *sc, in ath_chanctx_set_oneshot_noa() argument
478 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_set_oneshot_noa()
484 avp->noa_duration = duration + sc->sched.channel_switch_time; in ath_chanctx_set_oneshot_noa()
494 void ath_chanctx_event(struct ath_softc *sc, struct ieee80211_vif *vif, in ath_chanctx_event() argument
497 struct ath_hw *ah = sc->sc_ah; in ath_chanctx_event()
508 spin_lock_bh(&sc->chan_lock); in ath_chanctx_event()
511 sc->cur_chan->chandef.center_freq1, in ath_chanctx_event()
513 chanctx_state_string(sc->sched.state), in ath_chanctx_event()
514 chanctx_event_delta(sc)); in ath_chanctx_event()
529 if (avp->chanctx != sc->cur_chan) { in ath_chanctx_event()
535 if (sc->sched.offchannel_pending && !sc->sched.wait_switch) { in ath_chanctx_event()
536 sc->sched.offchannel_pending = false; in ath_chanctx_event()
537 sc->next_chan = &sc->offchannel.chan; in ath_chanctx_event()
538 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; in ath_chanctx_event()
543 ctx = ath_chanctx_get_next(sc, sc->cur_chan); in ath_chanctx_event()
544 if (ctx->active && sc->sched.state == ATH_CHANCTX_STATE_IDLE) { in ath_chanctx_event()
545 sc->next_chan = ctx; in ath_chanctx_event()
546 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; in ath_chanctx_event()
552 if (sc->sched.state == ATH_CHANCTX_STATE_WAIT_FOR_TIMER) { in ath_chanctx_event()
553 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; in ath_chanctx_event()
558 if (sc->sched.mgd_prepare_tx) in ath_chanctx_event()
559 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; in ath_chanctx_event()
568 sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) { in ath_chanctx_event()
576 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) in ath_chanctx_event()
581 sc->sched.beacon_pending = true; in ath_chanctx_event()
582 sc->sched.next_tbtt = REG_READ(ah, AR_NEXT_TBTT_TIMER); in ath_chanctx_event()
584 cur_conf = &sc->cur_chan->beacon; in ath_chanctx_event()
588 tsf_time = sc->sched.next_tbtt + beacon_int / 4; in ath_chanctx_event()
589 sc->sched.switch_start_time = tsf_time; in ath_chanctx_event()
590 sc->cur_chan->last_beacon = sc->sched.next_tbtt; in ath_chanctx_event()
597 if (sc->next_chan == &sc->offchannel.chan) { in ath_chanctx_event()
598 ath_chanctx_offchannel_noa(sc, ctx, avp, tsf_time); in ath_chanctx_event()
602 ath_chanctx_handle_bmiss(sc, ctx, avp); in ath_chanctx_event()
610 if (sc->sched.mgd_prepare_tx) { in ath_chanctx_event()
611 ath_chanctx_set_oneshot_noa(sc, avp, tsf_time, in ath_chanctx_event()
626 (!avp->noa_duration || sc->sched.force_noa_update)) in ath_chanctx_event()
627 ath_chanctx_set_periodic_noa(sc, avp, cur_conf, in ath_chanctx_event()
630 if (ctx->active && sc->sched.force_noa_update) in ath_chanctx_event()
631 sc->sched.force_noa_update = false; in ath_chanctx_event()
635 if (!sc->sched.beacon_pending) { in ath_chanctx_event()
641 sc->sched.beacon_pending = false; in ath_chanctx_event()
643 if (sc->sched.mgd_prepare_tx) { in ath_chanctx_event()
644 sc->sched.mgd_prepare_tx = false; in ath_chanctx_event()
645 complete(&sc->go_beacon); in ath_chanctx_event()
651 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_BEACON) in ath_chanctx_event()
657 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER; in ath_chanctx_event()
658 ath_chanctx_setup_timer(sc, sc->sched.switch_start_time); in ath_chanctx_event()
661 if (sc->sched.state != ATH_CHANCTX_STATE_WAIT_FOR_TIMER) in ath_chanctx_event()
664 if (!sc->cur_chan->switch_after_beacon && in ath_chanctx_event()
665 sc->sched.beacon_pending) in ath_chanctx_event()
666 sc->sched.beacon_miss++; in ath_chanctx_event()
671 sc->sched.state = ATH_CHANCTX_STATE_SWITCH; in ath_chanctx_event()
672 ieee80211_queue_work(sc->hw, &sc->chanctx_work); in ath_chanctx_event()
676 sc->cur_chan == &sc->offchannel.chan) in ath_chanctx_event()
679 sc->sched.beacon_pending = false; in ath_chanctx_event()
680 sc->sched.beacon_miss = 0; in ath_chanctx_event()
682 if (sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE || in ath_chanctx_event()
683 !sc->sched.beacon_adjust || in ath_chanctx_event()
684 !sc->cur_chan->tsf_val) in ath_chanctx_event()
687 ath_chanctx_adjust_tbtt_delta(sc); in ath_chanctx_event()
692 tsf_time = sc->sched.switch_start_time; in ath_chanctx_event()
693 tsf_time -= (u32) sc->cur_chan->tsf_val + in ath_chanctx_event()
694 ath9k_hw_get_tsf_offset(&sc->cur_chan->tsf_ts, NULL); in ath_chanctx_event()
697 sc->sched.beacon_adjust = false; in ath_chanctx_event()
698 ath_chanctx_setup_timer(sc, tsf_time); in ath_chanctx_event()
701 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE || in ath_chanctx_event()
702 avp->chanctx != sc->cur_chan) in ath_chanctx_event()
708 sc->sched.state = ATH_CHANCTX_STATE_IDLE; in ath_chanctx_event()
712 sc->sched.state == ATH_CHANCTX_STATE_FORCE_ACTIVE || in ath_chanctx_event()
713 sc->cur_chan->switch_after_beacon || in ath_chanctx_event()
714 sc->cur_chan == &sc->offchannel.chan) in ath_chanctx_event()
720 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan); in ath_chanctx_event()
721 cur_conf = &sc->cur_chan->beacon; in ath_chanctx_event()
726 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_TIMER; in ath_chanctx_event()
727 sc->sched.wait_switch = false; in ath_chanctx_event()
731 if (sc->sched.extend_absence) { in ath_chanctx_event()
732 sc->sched.beacon_miss = 0; in ath_chanctx_event()
736 tsf_time -= sc->sched.channel_switch_time; in ath_chanctx_event()
737 tsf_time += ath9k_hw_gettsf32(sc->sc_ah); in ath_chanctx_event()
738 sc->sched.switch_start_time = tsf_time; in ath_chanctx_event()
740 ath_chanctx_setup_timer(sc, tsf_time); in ath_chanctx_event()
741 sc->sched.beacon_pending = true; in ath_chanctx_event()
742 sc->sched.beacon_adjust = true; in ath_chanctx_event()
745 if (sc->cur_chan == &sc->offchannel.chan || in ath_chanctx_event()
746 sc->cur_chan->switch_after_beacon) in ath_chanctx_event()
749 sc->next_chan = ath_chanctx_get_next(sc, sc->cur_chan); in ath_chanctx_event()
750 ieee80211_queue_work(sc->hw, &sc->chanctx_work); in ath_chanctx_event()
753 if (sc->cur_chan->assigned) { in ath_chanctx_event()
754 if (sc->next_chan && !sc->next_chan->assigned && in ath_chanctx_event()
755 sc->next_chan != &sc->offchannel.chan) in ath_chanctx_event()
756 sc->sched.state = ATH_CHANCTX_STATE_IDLE; in ath_chanctx_event()
760 ctx = ath_chanctx_get_next(sc, sc->cur_chan); in ath_chanctx_event()
761 sc->sched.state = ATH_CHANCTX_STATE_IDLE; in ath_chanctx_event()
765 sc->next_chan = ctx; in ath_chanctx_event()
766 ieee80211_queue_work(sc->hw, &sc->chanctx_work); in ath_chanctx_event()
774 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_event()
777 void ath_chanctx_beacon_sent_ev(struct ath_softc *sc, in ath_chanctx_beacon_sent_ev() argument
780 if (sc->sched.beacon_pending) in ath_chanctx_beacon_sent_ev()
781 ath_chanctx_event(sc, NULL, ev); in ath_chanctx_beacon_sent_ev()
784 void ath_chanctx_beacon_recv_ev(struct ath_softc *sc, in ath_chanctx_beacon_recv_ev() argument
787 ath_chanctx_event(sc, NULL, ev); in ath_chanctx_beacon_recv_ev()
790 static int ath_scan_channel_duration(struct ath_softc *sc, in ath_scan_channel_duration() argument
793 struct cfg80211_scan_request *req = sc->offchannel.scan_req; in ath_scan_channel_duration()
801 static void ath_chanctx_switch(struct ath_softc *sc, struct ath_chanctx *ctx, in ath_chanctx_switch() argument
804 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_switch()
806 spin_lock_bh(&sc->chan_lock); in ath_chanctx_switch()
809 (sc->cur_chan != ctx) && (ctx == &sc->offchannel.chan)) { in ath_chanctx_switch()
813 sc->sched.offchannel_pending = true; in ath_chanctx_switch()
814 sc->sched.wait_switch = true; in ath_chanctx_switch()
815 sc->sched.offchannel_duration = in ath_chanctx_switch()
816 jiffies_to_usecs(sc->offchannel.duration) + in ath_chanctx_switch()
817 sc->sched.channel_switch_time; in ath_chanctx_switch()
819 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_switch()
825 sc->next_chan = ctx; in ath_chanctx_switch()
832 if (sc->next_chan == &sc->offchannel.chan) { in ath_chanctx_switch()
833 sc->sched.offchannel_duration = in ath_chanctx_switch()
834 jiffies_to_usecs(sc->offchannel.duration) + in ath_chanctx_switch()
835 sc->sched.channel_switch_time; in ath_chanctx_switch()
841 sc->sched.offchannel_duration); in ath_chanctx_switch()
844 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_switch()
845 ieee80211_queue_work(sc->hw, &sc->chanctx_work); in ath_chanctx_switch()
848 static void ath_chanctx_offchan_switch(struct ath_softc *sc, in ath_chanctx_offchan_switch() argument
851 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_offchan_switch()
858 ath_chanctx_switch(sc, &sc->offchannel.chan, &chandef); in ath_chanctx_offchan_switch()
861 static struct ath_chanctx *ath_chanctx_get_oper_chan(struct ath_softc *sc, in ath_chanctx_get_oper_chan() argument
866 ath_for_each_chanctx(sc, ctx) { in ath_chanctx_get_oper_chan()
876 return &sc->chanctx[0]; in ath_chanctx_get_oper_chan()
880 ath_scan_next_channel(struct ath_softc *sc) in ath_scan_next_channel() argument
882 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_scan_next_channel()
883 struct cfg80211_scan_request *req = sc->offchannel.scan_req; in ath_scan_next_channel()
886 if (sc->offchannel.scan_idx >= req->n_channels) { in ath_scan_next_channel()
890 sc->offchannel.scan_idx, in ath_scan_next_channel()
893 sc->offchannel.state = ATH_OFFCHANNEL_IDLE; in ath_scan_next_channel()
894 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), in ath_scan_next_channel()
901 sc->offchannel.scan_idx); in ath_scan_next_channel()
903 chan = req->channels[sc->offchannel.scan_idx++]; in ath_scan_next_channel()
904 sc->offchannel.duration = ath_scan_channel_duration(sc, chan); in ath_scan_next_channel()
905 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_SEND; in ath_scan_next_channel()
907 ath_chanctx_offchan_switch(sc, chan); in ath_scan_next_channel()
910 void ath_offchannel_next(struct ath_softc *sc) in ath_offchannel_next() argument
914 if (sc->offchannel.scan_req) { in ath_offchannel_next()
915 vif = sc->offchannel.scan_vif; in ath_offchannel_next()
916 sc->offchannel.chan.txpower = vif->bss_conf.txpower; in ath_offchannel_next()
917 ath_scan_next_channel(sc); in ath_offchannel_next()
918 } else if (sc->offchannel.roc_vif) { in ath_offchannel_next()
919 vif = sc->offchannel.roc_vif; in ath_offchannel_next()
920 sc->offchannel.chan.txpower = vif->bss_conf.txpower; in ath_offchannel_next()
921 sc->offchannel.duration = in ath_offchannel_next()
922 msecs_to_jiffies(sc->offchannel.roc_duration); in ath_offchannel_next()
923 sc->offchannel.state = ATH_OFFCHANNEL_ROC_START; in ath_offchannel_next()
924 ath_chanctx_offchan_switch(sc, sc->offchannel.roc_chan); in ath_offchannel_next()
926 spin_lock_bh(&sc->chan_lock); in ath_offchannel_next()
927 sc->sched.offchannel_pending = false; in ath_offchannel_next()
928 sc->sched.wait_switch = false; in ath_offchannel_next()
929 spin_unlock_bh(&sc->chan_lock); in ath_offchannel_next()
931 ath_chanctx_switch(sc, ath_chanctx_get_oper_chan(sc, false), in ath_offchannel_next()
933 sc->offchannel.state = ATH_OFFCHANNEL_IDLE; in ath_offchannel_next()
934 if (sc->ps_idle) in ath_offchannel_next()
935 ath_cancel_work(sc); in ath_offchannel_next()
939 void ath_roc_complete(struct ath_softc *sc, enum ath_roc_complete_reason reason) in ath_roc_complete() argument
941 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_roc_complete()
943 sc->offchannel.roc_vif = NULL; in ath_roc_complete()
944 sc->offchannel.roc_chan = NULL; in ath_roc_complete()
949 ieee80211_remain_on_channel_expired(sc->hw); in ath_roc_complete()
953 ieee80211_remain_on_channel_expired(sc->hw); in ath_roc_complete()
960 ath_offchannel_next(sc); in ath_roc_complete()
961 ath9k_ps_restore(sc); in ath_roc_complete()
964 void ath_scan_complete(struct ath_softc *sc, bool abort) in ath_scan_complete() argument
966 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_scan_complete()
976 sc->offchannel.scan_req = NULL; in ath_scan_complete()
977 sc->offchannel.scan_vif = NULL; in ath_scan_complete()
978 sc->offchannel.state = ATH_OFFCHANNEL_IDLE; in ath_scan_complete()
979 ieee80211_scan_completed(sc->hw, &info); in ath_scan_complete()
981 spin_lock_bh(&sc->chan_lock); in ath_scan_complete()
983 sc->sched.force_noa_update = true; in ath_scan_complete()
984 spin_unlock_bh(&sc->chan_lock); in ath_scan_complete()
985 ath_offchannel_next(sc); in ath_scan_complete()
986 ath9k_ps_restore(sc); in ath_scan_complete()
989 static void ath_scan_send_probe(struct ath_softc *sc, in ath_scan_send_probe() argument
992 struct cfg80211_scan_request *req = sc->offchannel.scan_req; in ath_scan_send_probe()
993 struct ieee80211_vif *vif = sc->offchannel.scan_vif; in ath_scan_send_probe()
997 int band = sc->offchannel.chan.chandef.chan->band; in ath_scan_send_probe()
999 skb = ieee80211_probereq_get(sc->hw, vif->addr, in ath_scan_send_probe()
1013 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, NULL)) in ath_scan_send_probe()
1016 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; in ath_scan_send_probe()
1017 if (ath_tx_start(sc->hw, skb, &txctl)) in ath_scan_send_probe()
1023 ieee80211_free_txskb(sc->hw, skb); in ath_scan_send_probe()
1026 static void ath_scan_channel_start(struct ath_softc *sc) in ath_scan_channel_start() argument
1028 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_scan_channel_start()
1029 struct cfg80211_scan_request *req = sc->offchannel.scan_req; in ath_scan_channel_start()
1032 if (!(sc->cur_chan->chandef.chan->flags & IEEE80211_CHAN_NO_IR) && in ath_scan_channel_start()
1035 ath_scan_send_probe(sc, &req->ssids[i]); in ath_scan_channel_start()
1042 sc->offchannel.state = ATH_OFFCHANNEL_PROBE_WAIT; in ath_scan_channel_start()
1043 mod_timer(&sc->offchannel.timer, jiffies + sc->offchannel.duration); in ath_scan_channel_start()
1048 struct ath_softc *sc = from_timer(sc, t, sched.timer); in ath_chanctx_timer() local
1049 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_timer()
1054 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER); in ath_chanctx_timer()
1059 struct ath_softc *sc = from_timer(sc, t, offchannel.timer); in ath_offchannel_timer() local
1061 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_offchannel_timer()
1064 __func__, offchannel_state_string(sc->offchannel.state)); in ath_offchannel_timer()
1066 switch (sc->offchannel.state) { in ath_offchannel_timer()
1068 if (!sc->offchannel.scan_req) in ath_offchannel_timer()
1072 ctx = ath_chanctx_get_oper_chan(sc, true); in ath_offchannel_timer()
1078 sc->offchannel.state = ATH_OFFCHANNEL_SUSPEND; in ath_offchannel_timer()
1079 ath_chanctx_switch(sc, ctx, NULL); in ath_offchannel_timer()
1080 mod_timer(&sc->offchannel.timer, jiffies + HZ / 10); in ath_offchannel_timer()
1085 if (!sc->offchannel.scan_req) in ath_offchannel_timer()
1088 ath_scan_next_channel(sc); in ath_offchannel_timer()
1092 sc->offchannel.state = ATH_OFFCHANNEL_ROC_DONE; in ath_offchannel_timer()
1093 ath_roc_complete(sc, ATH_ROC_COMPLETE_EXPIRE); in ath_offchannel_timer()
1101 ath_chanctx_send_vif_ps_frame(struct ath_softc *sc, struct ath_vif *avp, in ath_chanctx_send_vif_ps_frame() argument
1109 int band = sc->cur_chan->chandef.chan->band; in ath_chanctx_send_vif_ps_frame()
1116 skb = ieee80211_nullfunc_get(sc->hw, vif, -1, false); in ath_chanctx_send_vif_ps_frame()
1127 if (!ieee80211_tx_prepare_skb(sc->hw, vif, skb, band, &sta)) { in ath_chanctx_send_vif_ps_frame()
1137 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; in ath_chanctx_send_vif_ps_frame()
1139 if (ath_tx_start(sc->hw, skb, &txctl)) { in ath_chanctx_send_vif_ps_frame()
1140 ieee80211_free_txskb(sc->hw, skb); in ath_chanctx_send_vif_ps_frame()
1148 ath_chanctx_send_ps_frame(struct ath_softc *sc, bool powersave) in ath_chanctx_send_ps_frame() argument
1154 list_for_each_entry(avp, &sc->cur_chan->vifs, list) { in ath_chanctx_send_ps_frame()
1155 if (ath_chanctx_send_vif_ps_frame(sc, avp, powersave)) in ath_chanctx_send_ps_frame()
1163 static bool ath_chanctx_defer_switch(struct ath_softc *sc) in ath_chanctx_defer_switch() argument
1165 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_defer_switch()
1167 if (sc->cur_chan == &sc->offchannel.chan) in ath_chanctx_defer_switch()
1170 switch (sc->sched.state) { in ath_chanctx_defer_switch()
1174 if (!sc->cur_chan->switch_after_beacon) in ath_chanctx_defer_switch()
1180 sc->sched.state = ATH_CHANCTX_STATE_WAIT_FOR_BEACON; in ath_chanctx_defer_switch()
1189 static void ath_offchannel_channel_change(struct ath_softc *sc) in ath_offchannel_channel_change() argument
1191 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_offchannel_channel_change()
1194 __func__, offchannel_state_string(sc->offchannel.state)); in ath_offchannel_channel_change()
1196 switch (sc->offchannel.state) { in ath_offchannel_channel_change()
1198 if (!sc->offchannel.scan_req) in ath_offchannel_channel_change()
1201 if (sc->cur_chan->chandef.chan != in ath_offchannel_channel_change()
1202 sc->offchannel.chan.chandef.chan) in ath_offchannel_channel_change()
1205 ath_scan_channel_start(sc); in ath_offchannel_channel_change()
1208 if (!sc->offchannel.scan_req) in ath_offchannel_channel_change()
1211 ath_scan_complete(sc, false); in ath_offchannel_channel_change()
1214 if (sc->cur_chan != &sc->offchannel.chan) in ath_offchannel_channel_change()
1217 sc->offchannel.state = ATH_OFFCHANNEL_ROC_WAIT; in ath_offchannel_channel_change()
1218 mod_timer(&sc->offchannel.timer, in ath_offchannel_channel_change()
1219 jiffies + sc->offchannel.duration); in ath_offchannel_channel_change()
1220 ieee80211_ready_on_channel(sc->hw); in ath_offchannel_channel_change()
1229 void ath_chanctx_set_next(struct ath_softc *sc, bool force) in ath_chanctx_set_next() argument
1231 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath_chanctx_set_next()
1238 spin_lock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1239 if (!sc->next_chan) { in ath_chanctx_set_next()
1240 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1244 if (!force && ath_chanctx_defer_switch(sc)) { in ath_chanctx_set_next()
1245 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1252 sc->cur_chan->chandef.center_freq1, in ath_chanctx_set_next()
1253 sc->next_chan->chandef.center_freq1); in ath_chanctx_set_next()
1255 if (sc->cur_chan != sc->next_chan) { in ath_chanctx_set_next()
1258 sc->cur_chan->chandef.center_freq1); in ath_chanctx_set_next()
1259 sc->cur_chan->stopped = true; in ath_chanctx_set_next()
1260 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1262 if (sc->next_chan == &sc->offchannel.chan) { in ath_chanctx_set_next()
1267 ath9k_chanctx_stop_queues(sc, sc->cur_chan); in ath_chanctx_set_next()
1270 __ath9k_flush(sc->hw, ~0, true, false, false); in ath_chanctx_set_next()
1272 if (ath_chanctx_send_ps_frame(sc, true)) in ath_chanctx_set_next()
1273 __ath9k_flush(sc->hw, BIT(IEEE80211_AC_VO), in ath_chanctx_set_next()
1277 spin_lock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1279 if (sc->cur_chan != &sc->offchannel.chan) { in ath_chanctx_set_next()
1280 ktime_get_raw_ts64(&sc->cur_chan->tsf_ts); in ath_chanctx_set_next()
1281 sc->cur_chan->tsf_val = ath9k_hw_gettsf64(sc->sc_ah); in ath_chanctx_set_next()
1284 old_ctx = sc->cur_chan; in ath_chanctx_set_next()
1285 sc->cur_chan = sc->next_chan; in ath_chanctx_set_next()
1286 sc->cur_chan->stopped = false; in ath_chanctx_set_next()
1287 sc->next_chan = NULL; in ath_chanctx_set_next()
1289 if (!sc->sched.offchannel_pending) in ath_chanctx_set_next()
1290 sc->sched.offchannel_duration = 0; in ath_chanctx_set_next()
1292 if (sc->sched.state != ATH_CHANCTX_STATE_FORCE_ACTIVE) in ath_chanctx_set_next()
1293 sc->sched.state = ATH_CHANCTX_STATE_IDLE; in ath_chanctx_set_next()
1295 spin_unlock_bh(&sc->chan_lock); in ath_chanctx_set_next()
1297 if (sc->sc_ah->chip_fullsleep || in ath_chanctx_set_next()
1298 memcmp(&sc->cur_chandef, &sc->cur_chan->chandef, in ath_chanctx_set_next()
1299 sizeof(sc->cur_chandef))) { in ath_chanctx_set_next()
1302 __func__, sc->cur_chan->chandef.center_freq1); in ath_chanctx_set_next()
1303 ath_set_channel(sc); in ath_chanctx_set_next()
1305 sc->sched.channel_switch_time = in ath_chanctx_set_next()
1315 ath9k_chanctx_wake_queues(sc, old_ctx); in ath_chanctx_set_next()
1318 ath_chanctx_send_ps_frame(sc, false); in ath_chanctx_set_next()
1320 ath_offchannel_channel_change(sc); in ath_chanctx_set_next()
1321 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_SWITCH); in ath_chanctx_set_next()
1326 struct ath_softc *sc = container_of(work, struct ath_softc, in ath_chanctx_work() local
1328 mutex_lock(&sc->mutex); in ath_chanctx_work()
1329 ath_chanctx_set_next(sc, false); in ath_chanctx_work()
1330 mutex_unlock(&sc->mutex); in ath_chanctx_work()
1333 void ath9k_offchannel_init(struct ath_softc *sc) in ath9k_offchannel_init() argument
1336 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath9k_offchannel_init()
1347 ctx = &sc->offchannel.chan; in ath9k_offchannel_init()
1358 sc->offchannel.chan.offchannel = true; in ath9k_offchannel_init()
1361 void ath9k_init_channel_context(struct ath_softc *sc) in ath9k_init_channel_context() argument
1363 INIT_WORK(&sc->chanctx_work, ath_chanctx_work); in ath9k_init_channel_context()
1365 timer_setup(&sc->offchannel.timer, ath_offchannel_timer, 0); in ath9k_init_channel_context()
1366 timer_setup(&sc->sched.timer, ath_chanctx_timer, 0); in ath9k_init_channel_context()
1368 init_completion(&sc->go_beacon); in ath9k_init_channel_context()
1371 void ath9k_deinit_channel_context(struct ath_softc *sc) in ath9k_deinit_channel_context() argument
1373 cancel_work_sync(&sc->chanctx_work); in ath9k_deinit_channel_context()
1385 void ath9k_chanctx_stop_queues(struct ath_softc *sc, struct ath_chanctx *ctx) in ath9k_chanctx_stop_queues() argument
1387 struct ath_hw *ah = sc->sc_ah; in ath9k_chanctx_stop_queues()
1390 if (ctx == &sc->offchannel.chan) { in ath9k_chanctx_stop_queues()
1391 ieee80211_stop_queue(sc->hw, in ath9k_chanctx_stop_queues()
1392 sc->hw->offchannel_tx_hw_queue); in ath9k_chanctx_stop_queues()
1395 ieee80211_stop_queue(sc->hw, in ath9k_chanctx_stop_queues()
1400 ieee80211_stop_queue(sc->hw, sc->hw->queues - 2); in ath9k_chanctx_stop_queues()
1404 void ath9k_chanctx_wake_queues(struct ath_softc *sc, struct ath_chanctx *ctx) in ath9k_chanctx_wake_queues() argument
1406 struct ath_hw *ah = sc->sc_ah; in ath9k_chanctx_wake_queues()
1409 if (ctx == &sc->offchannel.chan) { in ath9k_chanctx_wake_queues()
1410 ieee80211_wake_queue(sc->hw, in ath9k_chanctx_wake_queues()
1411 sc->hw->offchannel_tx_hw_queue); in ath9k_chanctx_wake_queues()
1414 ieee80211_wake_queue(sc->hw, in ath9k_chanctx_wake_queues()
1419 ieee80211_wake_queue(sc->hw, sc->hw->queues - 2); in ath9k_chanctx_wake_queues()
1426 static void ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp) in ath9k_update_p2p_ps_timer() argument
1428 struct ath_common *common = ath9k_hw_common(sc->sc_ah); in ath9k_update_p2p_ps_timer()
1429 struct ath_hw *ah = sc->sc_ah; in ath9k_update_p2p_ps_timer()
1435 ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer); in ath9k_update_p2p_ps_timer()
1437 tsf = ath9k_hw_gettsf32(sc->sc_ah); in ath9k_update_p2p_ps_timer()
1452 ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, target_tsf, 1000000); in ath9k_update_p2p_ps_timer()
1455 static void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif) in ath9k_update_p2p_ps() argument
1460 if (!sc->p2p_ps_timer) in ath9k_update_p2p_ps()
1466 sc->p2p_ps_vif = avp; in ath9k_update_p2p_ps()
1468 if (sc->ps_flags & PS_BEACON_SYNC) in ath9k_update_p2p_ps()
1471 tsf = ath9k_hw_gettsf32(sc->sc_ah); in ath9k_update_p2p_ps()
1473 ath9k_update_p2p_ps_timer(sc, avp); in ath9k_update_p2p_ps()
1476 static u8 ath9k_get_ctwin(struct ath_softc *sc, struct ath_vif *avp) in ath9k_get_ctwin() argument
1478 struct ath_beacon_config *cur_conf = &sc->cur_chan->beacon; in ath9k_get_ctwin()
1500 void ath9k_beacon_add_noa(struct ath_softc *sc, struct ath_vif *avp, in ath9k_beacon_add_noa() argument
1530 noa->oppps_ctwindow = ath9k_get_ctwin(sc, avp); in ath9k_beacon_add_noa()
1536 u32 interval = TU_TO_USEC(sc->cur_chan->beacon.beacon_interval); in ath9k_beacon_add_noa()
1557 struct ath_softc *sc = priv; in ath9k_p2p_ps_timer() local
1558 struct ath_vif *avp = sc->p2p_ps_vif; in ath9k_p2p_ps_timer()
1564 del_timer_sync(&sc->sched.timer); in ath9k_p2p_ps_timer()
1565 ath9k_hw_gen_timer_stop(sc->sc_ah, sc->p2p_ps_timer); in ath9k_p2p_ps_timer()
1566 ath_chanctx_event(sc, NULL, ATH_CHANCTX_EVENT_TSF_TIMER); in ath9k_p2p_ps_timer()
1568 if (!avp || avp->chanctx != sc->cur_chan) in ath9k_p2p_ps_timer()
1571 tsf = ath9k_hw_gettsf32(sc->sc_ah); in ath9k_p2p_ps_timer()
1581 ath9k_update_p2p_ps_timer(sc, avp); in ath9k_p2p_ps_timer()
1596 ath_tx_aggr_sleep(sta, sc, an); in ath9k_p2p_ps_timer()
1598 ath_tx_aggr_wakeup(sc, an); in ath9k_p2p_ps_timer()
1604 void ath9k_p2p_bss_info_changed(struct ath_softc *sc, in ath9k_p2p_bss_info_changed() argument
1609 spin_lock_bh(&sc->sc_pcu_lock); in ath9k_p2p_bss_info_changed()
1610 spin_lock_irqsave(&sc->sc_pm_lock, flags); in ath9k_p2p_bss_info_changed()
1611 ath9k_update_p2p_ps(sc, vif); in ath9k_p2p_bss_info_changed()
1612 spin_unlock_irqrestore(&sc->sc_pm_lock, flags); in ath9k_p2p_bss_info_changed()
1613 spin_unlock_bh(&sc->sc_pcu_lock); in ath9k_p2p_bss_info_changed()
1616 void ath9k_p2p_beacon_sync(struct ath_softc *sc) in ath9k_p2p_beacon_sync() argument
1618 if (sc->p2p_ps_vif) in ath9k_p2p_beacon_sync()
1619 ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif); in ath9k_p2p_beacon_sync()
1622 void ath9k_p2p_remove_vif(struct ath_softc *sc, in ath9k_p2p_remove_vif() argument
1627 spin_lock_bh(&sc->sc_pcu_lock); in ath9k_p2p_remove_vif()
1628 if (avp == sc->p2p_ps_vif) { in ath9k_p2p_remove_vif()
1629 sc->p2p_ps_vif = NULL; in ath9k_p2p_remove_vif()
1630 ath9k_update_p2p_ps_timer(sc, NULL); in ath9k_p2p_remove_vif()
1632 spin_unlock_bh(&sc->sc_pcu_lock); in ath9k_p2p_remove_vif()
1635 int ath9k_init_p2p(struct ath_softc *sc) in ath9k_init_p2p() argument
1637 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer, in ath9k_init_p2p()
1638 NULL, sc, AR_FIRST_NDP_TIMER); in ath9k_init_p2p()
1639 if (!sc->p2p_ps_timer) in ath9k_init_p2p()
1645 void ath9k_deinit_p2p(struct ath_softc *sc) in ath9k_deinit_p2p() argument
1647 if (sc->p2p_ps_timer) in ath9k_deinit_p2p()
1648 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer); in ath9k_deinit_p2p()