1 From 6744d0a7ea037c7d65e13ca906da93009b241d00 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@openwrt.org>
3 Date: Tue, 11 Feb 2014 11:16:24 +0100
4 Subject: [PATCH] ath9k: implement p2p client powersave support
6 Use generic TSF timers to trigger powersave state changes based
7 information from the P2P NoA attribute.
8 Opportunistic Powersave is not handled, because the driver does not
9 support powersave at the moment.
11 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
13 drivers/net/wireless/ath/ath9k/ath9k.h | 12 ++++
14 drivers/net/wireless/ath/ath9k/init.c | 6 ++
15 drivers/net/wireless/ath/ath9k/main.c | 104 +++++++++++++++++++++++++++++++++
16 drivers/net/wireless/ath/ath9k/recv.c | 3 +
17 4 files changed, 125 insertions(+)
19 --- a/drivers/net/wireless/ath/ath9k/main.c
20 +++ b/drivers/net/wireless/ath/ath9k/main.c
21 @@ -261,6 +261,8 @@ static bool ath_complete_reset(struct at
23 ieee80211_wake_queues(sc->hw);
25 + ath9k_p2p_ps_timer(sc);
30 @@ -1126,6 +1128,8 @@ static int ath9k_add_interface(struct ie
31 if (ath9k_uses_beacons(vif->type))
32 ath9k_beacon_assign_slot(sc, vif);
39 @@ -1170,6 +1174,29 @@ static int ath9k_change_interface(struct
44 +ath9k_update_p2p_ps_timer(struct ath_softc *sc, struct ath_vif *avp)
46 + struct ath_hw *ah = sc->sc_ah;
47 + s32 tsf, target_tsf;
49 + if (!avp || !avp->noa.has_next_tsf)
52 + ath9k_hw_gen_timer_stop(ah, sc->p2p_ps_timer);
54 + tsf = ath9k_hw_gettsf32(sc->sc_ah);
56 + target_tsf = avp->noa.next_tsf;
57 + if (!avp->noa.absent)
58 + target_tsf -= ATH_P2P_PS_STOP_TIME;
60 + if (target_tsf - tsf < ATH_P2P_PS_STOP_TIME)
61 + target_tsf = tsf + ATH_P2P_PS_STOP_TIME;
63 + ath9k_hw_gen_timer_start(ah, sc->p2p_ps_timer, (u32) target_tsf, 1000000);
66 static void ath9k_remove_interface(struct ieee80211_hw *hw,
67 struct ieee80211_vif *vif)
69 @@ -1181,6 +1208,13 @@ static void ath9k_remove_interface(struc
71 mutex_lock(&sc->mutex);
73 + spin_lock_bh(&sc->sc_pcu_lock);
74 + if (avp == sc->p2p_ps_vif) {
75 + sc->p2p_ps_vif = NULL;
76 + ath9k_update_p2p_ps_timer(sc, NULL);
78 + spin_unlock_bh(&sc->sc_pcu_lock);
83 @@ -1649,6 +1683,70 @@ static void ath9k_bss_assoc_iter(void *d
84 ath9k_set_assoc_state(sc, vif);
87 +void ath9k_p2p_ps_timer(void *priv)
89 + struct ath_softc *sc = priv;
90 + struct ath_vif *avp = sc->p2p_ps_vif;
91 + struct ieee80211_vif *vif;
92 + struct ieee80211_sta *sta;
93 + struct ath_node *an;
99 + tsf = ath9k_hw_gettsf32(sc->sc_ah);
100 + if (!avp->noa.absent)
101 + tsf += ATH_P2P_PS_STOP_TIME;
103 + if (!avp->noa.has_next_tsf ||
104 + avp->noa.next_tsf - tsf > BIT(31))
105 + ieee80211_update_p2p_noa(&avp->noa, tsf);
107 + ath9k_update_p2p_ps_timer(sc, avp);
112 + sta = ieee80211_find_sta(vif, vif->bss_conf.bssid);
116 + an = (void *) sta->drv_priv;
117 + if (an->sleeping == !!avp->noa.absent)
120 + an->sleeping = avp->noa.absent;
122 + ath_tx_aggr_sleep(sta, sc, an);
124 + ath_tx_aggr_wakeup(sc, an);
130 +void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
132 + struct ath_vif *avp = (void *)vif->drv_priv;
135 + if (!sc->p2p_ps_timer)
138 + if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
141 + sc->p2p_ps_vif = avp;
143 + if (sc->ps_flags & PS_BEACON_SYNC)
146 + tsf = ath9k_hw_gettsf32(sc->sc_ah);
147 + ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
148 + ath9k_update_p2p_ps_timer(sc, avp);
151 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
152 struct ieee80211_vif *vif,
153 struct ieee80211_bss_conf *bss_conf,
154 @@ -1723,6 +1821,12 @@ static void ath9k_bss_info_changed(struc
158 + if (changed & BSS_CHANGED_P2P_PS) {
159 + spin_lock_bh(&sc->sc_pcu_lock);
160 + ath9k_update_p2p_ps(sc, vif);
161 + spin_unlock_bh(&sc->sc_pcu_lock);
164 if (changed & CHECK_ANI)
167 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
168 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
169 @@ -115,6 +115,9 @@ int ath_descdma_setup(struct ath_softc *
170 #define ATH_TXFIFO_DEPTH 8
171 #define ATH_TX_ERROR 0x01
173 +/* Stop tx traffic 1ms before the GO goes away */
174 +#define ATH_P2P_PS_STOP_TIME 1000
176 #define IEEE80211_SEQ_SEQ_SHIFT 4
177 #define IEEE80211_SEQ_MAX 4096
178 #define IEEE80211_WEP_IVLEN 3
179 @@ -363,11 +366,15 @@ void ath9k_release_buffered_frames(struc
183 + struct ieee80211_vif *vif;
184 struct ath_node mcast_node;
186 bool primary_sta_vif;
187 __le64 tsf_adjust; /* TSF adjustment for staggered beacons */
188 struct ath_buf *av_bcbuf;
191 + struct ieee80211_noa_data noa;
194 struct ath9k_vif_iter_data {
195 @@ -472,6 +479,8 @@ int ath_update_survey_stats(struct ath_s
196 void ath_update_survey_nf(struct ath_softc *sc, int channel);
197 void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
198 void ath_ps_full_sleep(unsigned long data);
199 +void ath9k_p2p_ps_timer(void *priv);
200 +void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif);
204 @@ -741,6 +750,9 @@ struct ath_softc {
205 struct completion paprd_complete;
206 wait_queue_head_t tx_wait;
208 + struct ath_gen_timer *p2p_ps_timer;
209 + struct ath_vif *p2p_ps_vif;
211 unsigned long sc_flags;
212 unsigned long driver_data;
214 --- a/drivers/net/wireless/ath/ath9k/init.c
215 +++ b/drivers/net/wireless/ath/ath9k/init.c
216 @@ -797,6 +797,9 @@ static int ath9k_init_softc(u16 devid, s
220 + sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
221 + NULL, sc, AR_FIRST_NDP_TIMER);
223 ath9k_cmn_init_crypto(sc->sc_ah);
225 ath_fill_led_pin(sc);
226 @@ -1082,6 +1085,9 @@ static void ath9k_deinit_softc(struct at
230 + if (sc->p2p_ps_timer)
231 + ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
233 ath9k_deinit_btcoex(sc);
235 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
236 --- a/drivers/net/wireless/ath/ath9k/recv.c
237 +++ b/drivers/net/wireless/ath/ath9k/recv.c
238 @@ -539,6 +539,9 @@ static void ath_rx_ps_beacon(struct ath_
240 "Reconfigure beacon timers based on synchronized timestamp\n");
241 ath9k_set_beacon(sc);
243 + if (sc->p2p_ps_vif)
244 + ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
247 if (ath_beacon_dtim_pending_cab(skb)) {