ath9k: Correct TSF adjustment to align the beacon time correctly
PATCH v2 1/6 ath9k: Correct TSF adjustment to align the beacon time correctly
From: Benjamin Berg <[email protected]>
Beacons were not send out at (timestamp % beacon_time == 0) for interfaces other than the primary one. To send out beacons with the correct timestamp according to 10.1.3.2 of the 802.11 standard the tsf_adjustment has to be set to the negative time difference instead of positive. This way the later beacons get corrected to have a lower (and similar) timestamp with regard to the beacon from slot 0.
I am not aware about any issues that have been caused by this.
--- drivers/net/wireless/ath/ath9k/beacon.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath9k/beacon.c +8 -4
@@ -279,17 +279,21 @@ static void ath9k_set_tsfadjust(struct ath_softc *sc, struct ieee80211_vif *vif)struct ath_common *common =ath9k_hw_common (sc->sc_ah);struct ath_vif *avp = (void *)vif->drv_priv;struct ath_beacon_config *cur_conf = &avp->chanctx->beacon; -u32 tsfadjust; +s64 tsfadjust;if (avp->av_bslot ==0 )return ; +/* tsf_adjust is added to the TSF value. We send out the beacon late, +* so need to adjust the TSF starting point to be later in time (i.e. +* the theoretical first beacon has a TSF of 0 after correction). +*/ tsfadjust = cur_conf->beacon_interval * avp->av_bslot; - tsfadjust =TU_TO_USEC (tsfadjust) /ATH_BCBUF ; + tsfadjust = -TU_TO_USEC (tsfadjust) /ATH_BCBUF ; avp->tsf_adjust =cpu_to_le64 (tsfadjust); -ath_dbg (common,CONFIG ,"tsfadjust is: %llu for bslot: %d\n" , - (unsigned long long )tsfadjust, avp->av_bslot); +ath_dbg (common,CONFIG ,"tsfadjust is: %lld for bslot: %d\n" , + (signed long long )tsfadjust, avp->av_bslot); }bool ath9k_csa_is_finished (struct ath_softc *sc,struct ieee80211_vif *vif)
Signature · 1 line
2.8.1
PATCH v2 2/6 ath9k: Handle channel context in get_/set_/reset_tsf
From: Benjamin Berg <[email protected]>
The ath9k TSF handling routines need to be aware of the channel context that is being modified. With this change the TSF related values that are stored in each channel context will be correctly tracked and the harware will only be updated if the modified context is currently the active one.
Without this change the TSF modifications done using these routines would for example be lost during a hardware reset as done by ath_complete_reset.
--- drivers/net/wireless/ath/ath9k/main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath9k/main.c +18 -3
@@ -1823,11 +1823,18 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,static u64 ath9k_get_tsf (struct ieee80211_hw *hw,struct ieee80211_vif *vif) {struct ath_softc *sc = hw->priv; +struct ath_vif *avp = (void *)vif->drv_priv;u64 tsf;mutex_lock (&sc->mutex);ath9k_ps_wakeup (sc); - tsf =ath9k_hw_gettsf64 (sc->sc_ah); +/* Get current TSF either from HW or kernel time. */ +if (sc->cur_chan == avp->chanctx) { + tsf =ath9k_hw_gettsf64 (sc->sc_ah); + }else { + tsf = sc->cur_chan->tsf_val + +ath9k_hw_get_tsf_offset (&sc->cur_chan->tsf_ts,NULL ); + }ath9k_ps_restore (sc);mutex_unlock (&sc->mutex);
@@ -1839,10 +1846,14 @@ static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf) {struct ath_softc *sc = hw->priv; +struct ath_vif *avp = (void *)vif->drv_priv;mutex_lock (&sc->mutex);ath9k_ps_wakeup (sc); -ath9k_hw_settsf64 (sc->sc_ah, tsf); +getrawmonotonic (&avp->chanctx->tsf_ts); +if (sc->cur_chan == avp->chanctx) +ath9k_hw_settsf64 (sc->sc_ah, tsf); + avp->chanctx->tsf_val = tsf;ath9k_ps_restore (sc);mutex_unlock (&sc->mutex); }
@@ -1850,11 +1861,15 @@ static void ath9k_set_tsf(struct ieee80211_hw *hw,static void ath9k_reset_tsf (struct ieee80211_hw *hw,struct ieee80211_vif *vif) {struct ath_softc *sc = hw->priv; +struct ath_vif *avp = (void *)vif->drv_priv;mutex_lock (&sc->mutex);ath9k_ps_wakeup (sc); -ath9k_hw_reset_tsf (sc->sc_ah); +getrawmonotonic (&avp->chanctx->tsf_ts); +if (sc->cur_chan == avp->chanctx) +ath9k_hw_reset_tsf (sc->sc_ah); + avp->chanctx->tsf_val =0 ;ath9k_ps_restore (sc);mutex_unlock (&sc->mutex);
Signature · 1 line
2.8.1
PATCH v2 3/6 ath9k: Use tsf offset helper in ath9k_hw_reset
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
These changes make ath9k_hw_reset more consistent with other places that handle the TSF value by using the same helper routine.
A slight improvement is to not assume that a fixed time of 1.5ms has passed for the initval writes when compared to the first write attempt. Instead the TSF value is re-calculated which will yield a higher accuracy of the restored TSF timer.
--- drivers/net/wireless/ath/ath9k/hw.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/ath/ath9k/hw.c +8 -8
@@ -1832,8 +1832,9 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,u32 saveLedState;u32 saveDefAntenna;u32 macStaId1; +struct timespec tsf_ts; +u32 tsf_offset;u64 tsf =0 ; -s64 usec =0 ;int r;bool start_mci_reset = false;bool save_fullsleep = ah->chip_fullsleep;
@@ -1877,8 +1878,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, macStaId1 =REG_READ (ah,AR_STA_ID1 ) &AR_STA_ID1_BASE_RATE_11B ;/* Save TSF before chip reset, a cold reset clears it */ +getrawmonotonic (&tsf_ts); tsf =ath9k_hw_gettsf64 (ah); - usec =ktime_to_us (ktime_get_raw ()); saveLedState = REG_READ(ah, AR_CFG_LED) & (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
@@ -1911,8 +1912,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan, }/* Restore TSF */ - usec =ktime_to_us (ktime_get_raw ()) - usec; -ath9k_hw_settsf64 (ah, tsf + usec); + tsf_offset =ath9k_hw_get_tsf_offset (&tsf_ts,NULL ); +ath9k_hw_settsf64 (ah, tsf + tsf_offset);if (AR_SREV_9280_20_OR_LATER (ah))REG_SET_BIT (ah,AR_GPIO_INPUT_EN_VAL ,AR_GPIO_JTAG_DISABLE );
@@ -1932,12 +1933,11 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,/* * Some AR91xx SoC devices frequently fail to accept TSF writes * right after the chip reset. When that happens, write a new -* value after the initvals have been applied, with an offset -* based on measured time difference +* value after the initvals have been applied. */ if (AR_SREV_9100 (ah) && (ath9k_hw_gettsf64 (ah) < tsf)) { - tsf +=1500 ; -ath9k_hw_settsf64 (ah, tsf); + tsf_offset =ath9k_hw_get_tsf_offset (&tsf_ts,NULL ); +ath9k_hw_settsf64 (ah, tsf + tsf_offset); }ath9k_hw_init_mfp (ah);
Signature · 1 line
2.8.1
PATCH v2 4/6 ath9k: Expose tsf_adjustment in mac80211 tsf getters and setters.
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
The ath9k driver modifies the TSF for VIFs for the purpose of sending beacons in a staggered fashion. This patch exposes this VIF specific adjustment of the TSF value to mac80211. Without the change the TSF routines handle the hardware TSF value instead of the actual TSF value as seen on the air.
--- drivers/net/wireless/ath/ath9k/main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wireless/ath/ath9k/main.c +2 -0
@@ -1835,6 +1835,7 @@ static u64 ath9k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif) tsf = sc->cur_chan->tsf_val +ath9k_hw_get_tsf_offset (&sc->cur_chan->tsf_ts,NULL ); } + tsf +=le64_to_cpu (avp->tsf_adjust);ath9k_ps_restore (sc);mutex_unlock (&sc->mutex);
@@ -1850,6 +1851,7 @@ static void ath9k_set_tsf(struct ieee80211_hw *hw,mutex_lock (&sc->mutex);ath9k_ps_wakeup (sc); + tsf -=le64_to_cpu (avp->tsf_adjust);getrawmonotonic (&avp->chanctx->tsf_ts);if (sc->cur_chan == avp->chanctx)ath9k_hw_settsf64 (sc->sc_ah, tsf);
Signature · 1 line
2.8.1
PATCH v2 5/6 ath9k: Remove some #defined constants to decrease verbosity
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
The removed ATH9K_SLOT_TIME_X constants simply map the value in microseconds to the same integer. These constants were not used consistently, so fix the inconsistency issue by replacing all occurances with the integer equivalent.
--- drivers/net/wireless/ath/ath9k/beacon.c | 2 +- drivers/net/wireless/ath/ath9k/dynack.c | 4 ++-- drivers/net/wireless/ath/ath9k/htc_drv_beacon.c | 2 +- drivers/net/wireless/ath/ath9k/htc_drv_init.c | 2 +- drivers/net/wireless/ath/ath9k/hw.c | 2 +- drivers/net/wireless/ath/ath9k/init.c | 2 +- drivers/net/wireless/ath/ath9k/mac.h | 4 ---- drivers/net/wireless/ath/ath9k/main.c | 7 ++++--- 8 files changed, 11 insertions(+), 14 deletions(-)
drivers/net/wireless/ath/ath9k/beacon.c +1 -1
@@ -50,7 +50,7 @@ static void ath9k_beaconq_config(struct ath_softc *sc) txq = sc->tx.txq_map[IEEE80211_AC_BE ];ath9k_hw_get_txq_props (ah, txq->axq_qnum, &qi_be); qi.tqi_aifs = qi_be.tqi_aifs; -if (ah->slottime ==ATH9K_SLOT_TIME_20 ) +if (ah->slottime ==20 ) qi.tqi_cwmin =2 *qi_be.tqi_cwmin;else qi.tqi_cwmin =4 *qi_be.tqi_cwmin;
drivers/net/wireless/ath/ath9k/dynack.c +2 -2
@@ -280,7 +280,7 @@ EXPORT_SYMBOL(ath_dynack_sample_ack_ts);void ath_dynack_node_init (struct ath_hw *ah,struct ath_node *an) {/* ackto = slottime + sifs + air delay */ -u32 ackto =ATH9K_SLOT_TIME_9 +16 +64 ; +u32 ackto =9 +16 +64 ;struct ath_dynack *da = &ah->dynack; an->ackto = ackto;
@@ -315,7 +315,7 @@ EXPORT_SYMBOL(ath_dynack_node_deinit);void ath_dynack_reset (struct ath_hw *ah) {/* ackto = slottime + sifs + air delay */ -u32 ackto =ATH9K_SLOT_TIME_9 +16 +64 ; +u32 ackto =9 +16 +64 ;struct ath_dynack *da = &ah->dynack; da->lto = jiffies;
drivers/net/wireless/ath/ath9k/htc_drv_beacon.c +1 -1
@@ -45,7 +45,7 @@ void ath9k_htc_beaconq_config(struct ath9k_htc_priv *priv)* Long slot time : 2x cwmin * Short slot time : 4x cwmin */ -if (ah->slottime ==ATH9K_SLOT_TIME_20 ) +if (ah->slottime ==20 ) qi.tqi_cwmin =2 *qi_be.tqi_cwmin;else qi.tqi_cwmin =4 *qi_be.tqi_cwmin;
drivers/net/wireless/ath/ath9k/htc_drv_init.c +1 -1
@@ -678,7 +678,7 @@ static int ath9k_init_priv(struct ath9k_htc_priv *priv,for (i =0 ; i <ATH9K_HTC_MAX_BCN_VIF ; i++) priv->beacon.bslot[i] =NULL ; - priv->beacon.slottime =ATH9K_SLOT_TIME_9 ; + priv->beacon.slottime =9 ;ath9k_cmn_init_channels_rates (common);ath9k_cmn_init_crypto (ah);
drivers/net/wireless/ath/ath9k/hw.c +1 -1
@@ -454,7 +454,7 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)if (AR_SREV_9100 (ah)) ah->sta_id1_defaults |=AR_STA_ID1_AR9100_BA_FIX ; - ah->slottime =ATH9K_SLOT_TIME_9 ; + ah->slottime =9 ; ah->globaltxtimeout = (u32) -1 ; ah->power_mode =ATH9K_PM_UNDEFINED ; ah->htc_reset_init = true;
drivers/net/wireless/ath/ath9k/init.c +1 -1
@@ -372,7 +372,7 @@ static void ath9k_init_misc(struct ath_softc *sc) common->last_rssi =ATH_RSSI_DUMMY_MARKER ;memcpy (common->bssidmask, ath_bcast_mac,ETH_ALEN ); - sc->beacon.slottime =ATH9K_SLOT_TIME_9 ; + sc->beacon.slottime =9 ;for (i =0 ; i <ARRAY_SIZE (sc->beacon.bslot); i++) sc->beacon.bslot[i] =NULL ;
drivers/net/wireless/ath/ath9k/mac.h +0 -4
@@ -65,10 +65,6 @@#define INIT_SSH_RETRY 32#define INIT_SLG_RETRY 32 -#define ATH9K_SLOT_TIME_6 6 -#define ATH9K_SLOT_TIME_9 9 -#define ATH9K_SLOT_TIME_20 20 -#define ATH9K_TXERR_XRETRY 0x01#define ATH9K_TXERR_FILT 0x02#define ATH9K_TXERR_FIFO 0x04
drivers/net/wireless/ath/ath9k/main.c +4 -3
@@ -926,7 +926,7 @@ static void ath9k_vif_iter(struct ath9k_vif_iter_data *iter_data, }if (!vif->bss_conf.use_short_slot) - iter_data->slottime =ATH9K_SLOT_TIME_20 ; + iter_data->slottime =20 ;switch (vif->type) {case NL80211_IFTYPE_AP :
@@ -999,7 +999,7 @@ void ath9k_calculate_iter_data(struct ath_softc *sc,*/ memset (iter_data,0 ,sizeof (*iter_data));eth_broadcast_addr (iter_data->mask); - iter_data->slottime =ATH9K_SLOT_TIME_9 ; + iter_data->slottime =9 ;list_for_each_entry (avp, &ctx->vifs, list)ath9k_vif_iter (iter_data, avp->vif->addr, avp->vif);
@@ -1061,7 +1061,7 @@ static void ath9k_set_offchannel_state(struct ath_softc *sc) ah->opmode = vif->type; ah->imask &= ~ATH9K_INT_SWBA ; ah->imask &= ~ATH9K_INT_TSFOOR ; - ah->slottime =ATH9K_SLOT_TIME_9 ; + ah->slottime =9 ;ath_hw_setbssidmask (common);ath9k_hw_setopmode (ah);
@@ -1788,6 +1788,7 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw, slottime =9 ; else slottime =20 ; +if (vif->type ==NL80211_IFTYPE_AP ) {/* * Defer update, so that connected stations can adjust
Signature · 1 line
2.8.1
PATCH v2 6/6 ath9k: Fix beacon configuration for addition/removal of interfaces
In reply to Benjamin BergFrom: Benjamin Berg <[email protected]>
This patch fixes some issues with interface reconfiguration. It could for example happen that an AP interface in beacon slot 0 was removed leaving an IBSS station in one of the other slots. When this happens the driver never sends out the beacon as it only tries to send a beacon from slot 0.
Appart from that the tracking of required changes to the beacon config is relatively complicated and prone to errors.
The approach taken here is to solve reconfiguration issues is to reconfigure the beacons when any interface changes. This means that the complexity of deciding whether an interface change may modify the beacon configuration is gone. It also means that the beacon config will be reliably updated when an interface is removed.
The issue that a single non-AP interface might not be in beacon slot 0 and wouldn't be send out is solved by moving it into the first slot. The TSF value in hardware is adjusted accordingly so that the timestamp of the beacons stay consistent.
--- drivers/net/wireless/ath/ath9k/ath9k.h | 7 +- drivers/net/wireless/ath/ath9k/beacon.c | 240 ++++++++++++++++++-------------- drivers/net/wireless/ath/ath9k/common.h | 1 + drivers/net/wireless/ath/ath9k/main.c | 43 +++--- 4 files changed, 165 insertions(+), 126 deletions(-)
drivers/net/wireless/ath/ath9k/ath9k.h +5 -2
@@ -637,6 +637,8 @@ struct ath9k_vif_iter_data {int nwds;/* number of WDS vifs */ int nadhocs;/* number of adhoc vifs */ int nocbs;/* number of OCB vifs */ +int nbcnvifs;/* number of beaconing vifs */ +struct ieee80211_vif *primary_beacon_vif;struct ieee80211_vif *primary_sta; };
@@ -685,10 +687,11 @@ struct ath_beacon { };void ath9k_beacon_tasklet (unsigned long data); -void ath9k_beacon_config (struct ath_softc *sc,struct ieee80211_vif *vif, -u32 changed); +void ath9k_beacon_config (struct ath_softc *sc,struct ieee80211_vif *main_vif, +bool beacons);void ath9k_beacon_assign_slot (struct ath_softc *sc,struct ieee80211_vif *vif);void ath9k_beacon_remove_slot (struct ath_softc *sc,struct ieee80211_vif *vif); +void ath9k_beacon_ensure_primary_slot (struct ath_softc *sc);void ath9k_set_beacon (struct ath_softc *sc);bool ath9k_csa_is_finished (struct ath_softc *sc,struct ieee80211_vif *vif);void ath9k_csa_update (struct ath_softc *sc);
drivers/net/wireless/ath/ath9k/beacon.c +133 -107
358 lines not on this page · raw message
drivers/net/wireless/ath/ath9k/common.h +1 -0
@@ -50,6 +50,7 @@#define IEEE80211_MS_TO_TU (x) (((x) * 1000) / 1024)struct ath_beacon_config { +struct ieee80211_vif *main_vif;int beacon_interval;u16 dtim_period;u16 bmiss_timeout;
drivers/net/wireless/ath/ath9k/main.c +26 -17
102 lines not on this page · raw message
Signature · 1 line
2.8.1
PATCH v2 1/6 ath9k: Correct TSF adjustment to align the beacon time correctly
In reply to Benjamin BergQuoted 9 lines · Benjamin Berg
From: Benjamin Berg <[email protected]>
Beacons were not send out at (timestamp %
beacon_time== 0) for interfaces other than the primary one. To send out beacons with the correct timestamp according to 10.1.3.2 of the 802.11 standard thetsf_adjustmenthas to be set to the negative time difference instead of positive. This way the later beacons get corrected to have a lower (and similar) timestamp with regard to the beacon from slot 0.
Quoted 3 lines
I am not aware about any issues that have been caused by this.
Signed-off-by Benjamin Berg <[email protected]>
Thanks, 6 patches applied to ath-next branch of ath.git:
fa5106e1d793 ath9k: Correct TSF adjustment to align the beacon time correctly 9580cb889f35 ath9k: Handle channel context in get_/set_/reset_tsf bec9a94bc4e2 ath9k: Use tsf offset helper in ath9k_hw_reset 7fde51227aed ath9k: Expose tsf_adjustment in mac80211 tsf getters and setters. 11b0ac2e0c1c ath9k: Remove some #defined constants to decrease verbosity cfda2d8e2314 ath9k: Fix beacon configuration for addition/removal of interfaces
Signature · 2 lines
Sent by pwcli https://patchwork.kernel.org/patch/9212535/