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 @@ -1128,6 +1130,8 @@ static int ath9k_add_interface(struct ie
31 if (ath9k_uses_beacons(vif->type))
32 ath9k_beacon_assign_slot(sc, vif);
39 @@ -1172,6 +1176,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 @@ -1183,6 +1210,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,72 @@ 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;
133 + unsigned long flags;
136 + if (!sc->p2p_ps_timer)
139 + if (vif->type != NL80211_IFTYPE_STATION || !vif->p2p)
142 + sc->p2p_ps_vif = avp;
144 + spin_lock_irqsave(&sc->sc_pm_lock, flags);
145 + 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);
150 + spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
153 static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
154 struct ieee80211_vif *vif,
155 struct ieee80211_bss_conf *bss_conf,
156 @@ -1723,6 +1823,12 @@ static void ath9k_bss_info_changed(struc
160 + if (changed & BSS_CHANGED_P2P_PS) {
161 + spin_lock_bh(&sc->sc_pcu_lock);
162 + ath9k_update_p2p_ps(sc, vif);
163 + spin_unlock_bh(&sc->sc_pcu_lock);
166 if (changed & CHECK_ANI)
169 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
170 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
171 @@ -114,6 +114,9 @@ int ath_descdma_setup(struct ath_softc *
172 #define ATH_TXFIFO_DEPTH 8
173 #define ATH_TX_ERROR 0x01
175 +/* Stop tx traffic 1ms before the GO goes away */
176 +#define ATH_P2P_PS_STOP_TIME 1000
178 #define IEEE80211_SEQ_SEQ_SHIFT 4
179 #define IEEE80211_SEQ_MAX 4096
180 #define IEEE80211_WEP_IVLEN 3
181 @@ -366,11 +369,15 @@ void ath9k_release_buffered_frames(struc
185 + struct ieee80211_vif *vif;
186 struct ath_node mcast_node;
188 bool primary_sta_vif;
189 __le64 tsf_adjust; /* TSF adjustment for staggered beacons */
190 struct ath_buf *av_bcbuf;
193 + struct ieee80211_noa_data noa;
196 struct ath9k_vif_iter_data {
197 @@ -463,6 +470,8 @@ int ath_update_survey_stats(struct ath_s
198 void ath_update_survey_nf(struct ath_softc *sc, int channel);
199 void ath9k_queue_reset(struct ath_softc *sc, enum ath_reset_type type);
200 void ath_ps_full_sleep(unsigned long data);
201 +void ath9k_p2p_ps_timer(void *priv);
202 +void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif);
206 @@ -723,6 +732,9 @@ struct ath_softc {
207 struct completion paprd_complete;
208 wait_queue_head_t tx_wait;
210 + struct ath_gen_timer *p2p_ps_timer;
211 + struct ath_vif *p2p_ps_vif;
213 unsigned long driver_data;
216 --- a/drivers/net/wireless/ath/ath9k/init.c
217 +++ b/drivers/net/wireless/ath/ath9k/init.c
218 @@ -593,6 +593,9 @@ static int ath9k_init_softc(u16 devid, s
222 + sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
223 + NULL, sc, AR_FIRST_NDP_TIMER);
225 ath9k_cmn_init_crypto(sc->sc_ah);
227 ath_fill_led_pin(sc);
228 @@ -875,6 +878,9 @@ static void ath9k_deinit_softc(struct at
232 + if (sc->p2p_ps_timer)
233 + ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
235 ath9k_deinit_btcoex(sc);
237 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
238 --- a/drivers/net/wireless/ath/ath9k/recv.c
239 +++ b/drivers/net/wireless/ath/ath9k/recv.c
240 @@ -539,6 +539,9 @@ static void ath_rx_ps_beacon(struct ath_
242 "Reconfigure beacon timers based on synchronized timestamp\n");
243 ath9k_set_beacon(sc);
245 + if (sc->p2p_ps_vif)
246 + ath9k_update_p2p_ps(sc, sc->p2p_ps_vif->vif);
249 if (ath_beacon_dtim_pending_cab(skb)) {