diff options
Diffstat (limited to 'sys/dev/ath/if_ath_tdma.c')
-rw-r--r-- | sys/dev/ath/if_ath_tdma.c | 176 |
1 files changed, 170 insertions, 6 deletions
diff --git a/sys/dev/ath/if_ath_tdma.c b/sys/dev/ath/if_ath_tdma.c index 1d04ccd..5cfe238 100644 --- a/sys/dev/ath/if_ath_tdma.c +++ b/sys/dev/ath/if_ath_tdma.c @@ -115,6 +115,10 @@ __FBSDID("$FreeBSD$"); #include <dev/ath/ath_tx99/ath_tx99.h> #endif +#ifdef ATH_DEBUG_ALQ +#include <dev/ath/if_ath_alq.h> +#endif + #ifdef IEEE80211_SUPPORT_TDMA #include <dev/ath/if_ath_tdma.h> @@ -138,6 +142,45 @@ ath_tdma_settimers(struct ath_softc *sc, u_int32_t nexttbtt, u_int32_t bintval) bt.bt_nextatim = nexttbtt+1; /* Enables TBTT, DBA, SWBA timers by default */ bt.bt_flags = 0; +#if 0 + DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, + "%s: intval=%d (0x%08x) nexttbtt=%u (0x%08x), nextdba=%u (0x%08x), nextswba=%u (0x%08x),nextatim=%u (0x%08x)\n", + __func__, + bt.bt_intval, + bt.bt_intval, + bt.bt_nexttbtt, + bt.bt_nexttbtt, + bt.bt_nextdba, + bt.bt_nextdba, + bt.bt_nextswba, + bt.bt_nextswba, + bt.bt_nextatim, + bt.bt_nextatim); +#endif + +#ifdef ATH_DEBUG_ALQ + if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_TDMA_TIMER_SET)) { + struct if_ath_alq_tdma_timer_set t; + t.bt_intval = htobe32(bt.bt_intval); + t.bt_nexttbtt = htobe32(bt.bt_nexttbtt); + t.bt_nextdba = htobe32(bt.bt_nextdba); + t.bt_nextswba = htobe32(bt.bt_nextswba); + t.bt_nextatim = htobe32(bt.bt_nextatim); + t.bt_flags = htobe32(bt.bt_flags); + t.sc_tdmadbaprep = htobe32(sc->sc_tdmadbaprep); + t.sc_tdmaswbaprep = htobe32(sc->sc_tdmaswbaprep); + if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TDMA_TIMER_SET, + sizeof(t), (char *) &t); + } +#endif + + DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, + "%s: nexttbtt=%u (0x%08x), nexttbtt tsf=%lld (0x%08llx)\n", + __func__, + bt.bt_nexttbtt, + bt.bt_nexttbtt, + (long long) ( ((u_int64_t) (bt.bt_nexttbtt)) << 10), + (long long) ( ((u_int64_t) (bt.bt_nexttbtt)) << 10)); ath_hal_beaconsettimers(ah, &bt); } @@ -258,6 +301,23 @@ ath_tdma_config(struct ath_softc *sc, struct ieee80211vap *vap) tdma->tdma_slot, tdma->tdma_slotlen, tdma->tdma_slotcnt, tdma->tdma_bintval, sc->sc_tdmaguard, sc->sc_tdmabintval, sc->sc_tdmadbaprep); + +#ifdef ATH_DEBUG_ALQ + if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_TDMA_TIMER_CONFIG)) { + struct if_ath_alq_tdma_timer_config t; + + t.tdma_slot = htobe32(tdma->tdma_slot); + t.tdma_slotlen = htobe32(tdma->tdma_slotlen); + t.tdma_slotcnt = htobe32(tdma->tdma_slotcnt); + t.tdma_bintval = htobe32(tdma->tdma_bintval); + t.tdma_guard = htobe32(sc->sc_tdmaguard); + t.tdma_scbintval = htobe32(sc->sc_tdmabintval); + t.tdma_dbaprep = htobe32(sc->sc_tdmadbaprep); + + if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TDMA_TIMER_CONFIG, + sizeof(t), (char *) &t); + } +#endif /* ATH_DEBUG_ALQ */ } /* @@ -268,6 +328,16 @@ ath_tdma_config(struct ath_softc *sc, struct ieee80211vap *vap) * beacon timers so we follow their schedule. Note that * by using the rx timestamp we implicitly include the * propagation delay in our schedule. + * + * XXX TODO: since the changes for the AR5416 and later chips + * involved changing the TSF/TU calculations, we need to make + * sure that various calculations wrap consistently. + * + * A lot of the problems stemmed from the calculations wrapping + * at 65,535 TU. Since a lot of the math is still being done in + * TU, please audit it to ensure that when the TU values programmed + * into the timers wrap at (2^31)-1 TSF, all the various terms + * wrap consistently. */ void ath_tdma_update(struct ieee80211_node *ni, @@ -281,7 +351,7 @@ ath_tdma_update(struct ieee80211_node *ni, struct ath_softc *sc = ic->ic_ifp->if_softc; struct ath_hal *ah = sc->sc_ah; const HAL_RATE_TABLE *rt = sc->sc_currates; - u_int64_t tsf, rstamp, nextslot, nexttbtt; + u_int64_t tsf, rstamp, nextslot, nexttbtt, nexttbtt_full; u_int32_t txtime, nextslottu; int32_t tudelta, tsfdelta; const struct ath_rx_status *rs; @@ -326,9 +396,13 @@ ath_tdma_update(struct ieee80211_node *ni, rt->info[rix].shortPreamble); /* NB: << 9 is to cvt to TU and /2 */ nextslot = (rstamp - txtime) + (sc->sc_tdmabintval << 9); - nextslottu = TSF_TO_TU(nextslot>>32, nextslot) & HAL_BEACON_PERIOD; /* + * For 802.11n chips: nextslottu needs to be the full TSF space, + * not just 0..65535 TU. + */ + nextslottu = TSF_TO_TU(nextslot>>32, nextslot); + /* * Retrieve the hardware NextTBTT in usecs * and calculate the difference between what the * other station thinks and what we have programmed. This @@ -336,11 +410,47 @@ ath_tdma_update(struct ieee80211_node *ni, * adjustments are done by pulling the TSF forward and possibly * rewriting the beacon timers. */ - nexttbtt = ath_hal_getnexttbtt(ah); + /* + * The logic here assumes the nexttbtt counter is in TSF + * but the prr-11n NICs are in TU. The HAL shifts them + * to TSF but there's two important differences: + * + * + The TU->TSF values have 0's for the low 9 bits, and + * + The counter wraps at TU_TO_TSF(HAL_BEACON_PERIOD + 1) for + * the pre-11n NICs, but not for the 11n NICs. + * + * So for now, just make sure the nexttbtt value we get + * matches the second issue or once nexttbtt exceeds this + * value, tsfdelta ends up becoming very negative and all + * of the adjustments get very messed up. + */ + + /* + * We need to track the full nexttbtt rather than having it + * truncated at HAL_BEACON_PERIOD, as programming the + * nexttbtt (and related) registers for the 11n chips is + * actually going to take the full 32 bit space, rather than + * just 0..65535 TU. + */ + nexttbtt_full = ath_hal_getnexttbtt(ah); + nexttbtt = nexttbtt_full % (TU_TO_TSF(HAL_BEACON_PERIOD + 1)); tsfdelta = (int32_t)((nextslot % TU_TO_TSF(HAL_BEACON_PERIOD + 1)) - nexttbtt); DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, - "tsfdelta %d avg +%d/-%d\n", tsfdelta, + "rs->rstamp %llu rstamp %llu tsf %llu txtime %d, nextslot %llu, " + "nextslottu %d, nextslottume %d\n", + (unsigned long long) rs->rs_tstamp, rstamp, tsf, txtime, + nextslot, nextslottu, TSF_TO_TU(nextslot >> 32, nextslot)); + DPRINTF(sc, ATH_DEBUG_TDMA, + " beacon tstamp: %llu (0x%016llx)\n", + le64toh(ni->ni_tstamp.tsf), + le64toh(ni->ni_tstamp.tsf)); + + DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, + "nexttbtt %llu (0x%08llx) tsfdelta %d avg +%d/-%d\n", + nexttbtt, + (long long) nexttbtt, + tsfdelta, TDMA_AVG(sc->sc_avgtsfdeltap), TDMA_AVG(sc->sc_avgtsfdeltam)); if (tsfdelta < 0) { @@ -357,7 +467,34 @@ ath_tdma_update(struct ieee80211_node *ni, TDMA_SAMPLE(sc->sc_avgtsfdeltap, 0); TDMA_SAMPLE(sc->sc_avgtsfdeltam, 0); } - tudelta = nextslottu - TSF_TO_TU(nexttbtt >> 32, nexttbtt); + tudelta = nextslottu - TSF_TO_TU(nexttbtt_full >> 32, nexttbtt_full); + +#ifdef ATH_DEBUG_ALQ + if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_TDMA_BEACON_STATE)) { + struct if_ath_alq_tdma_beacon_state t; + t.rx_tsf = htobe64(rstamp); + t.beacon_tsf = htobe64(le64toh(ni->ni_tstamp.tsf)); + t.tsf64 = htobe64(tsf); + t.nextslot_tsf = htobe64(nextslot); + t.nextslot_tu = htobe32(nextslottu); + t.txtime = htobe32(txtime); + if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TDMA_BEACON_STATE, + sizeof(t), (char *) &t); + } + + if (if_ath_alq_checkdebug(&sc->sc_alq, ATH_ALQ_TDMA_SLOT_CALC)) { + struct if_ath_alq_tdma_slot_calc t; + + t.nexttbtt = htobe64(nexttbtt_full); + t.next_slot = htobe64(nextslot); + t.tsfdelta = htobe32(tsfdelta); + t.avg_plus = htobe32(TDMA_AVG(sc->sc_avgtsfdeltap)); + t.avg_minus = htobe32(TDMA_AVG(sc->sc_avgtsfdeltam)); + + if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TDMA_SLOT_CALC, + sizeof(t), (char *) &t); + } +#endif /* * Copy sender's timetstamp into tdma ie so they can @@ -388,11 +525,38 @@ ath_tdma_update(struct ieee80211_node *ni, * This basically filters out jumps due to missed beacons. */ if (tudelta != 0 && (tudelta > 0 || -tudelta < sc->sc_tdmabintval)) { + DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, + "%s: calling ath_tdma_settimers; nextslottu=%d, bintval=%d\n", + __func__, + nextslottu, + sc->sc_tdmabintval); ath_tdma_settimers(sc, nextslottu, sc->sc_tdmabintval); sc->sc_stats.ast_tdma_timers++; } if (tsfdelta > 0) { - ath_hal_adjusttsf(ah, tsfdelta); + uint64_t tsf; + + /* XXX should just teach ath_hal_adjusttsf() to do this */ + tsf = ath_hal_gettsf64(ah); + ath_hal_settsf64(ah, tsf + tsfdelta); + DPRINTF(sc, ATH_DEBUG_TDMA_TIMER, + "%s: calling ath_hal_adjusttsf: TSF=%llu, tsfdelta=%d\n", + __func__, + tsf, + tsfdelta); + +#ifdef ATH_DEBUG_ALQ + if (if_ath_alq_checkdebug(&sc->sc_alq, + ATH_ALQ_TDMA_TSF_ADJUST)) { + struct if_ath_alq_tdma_tsf_adjust t; + + t.tsfdelta = htobe32(tsfdelta); + t.tsf64_old = htobe64(tsf); + t.tsf64_new = htobe64(tsf + tsfdelta); + if_ath_alq_post(&sc->sc_alq, ATH_ALQ_TDMA_TSF_ADJUST, + sizeof(t), (char *) &t); + } +#endif /* ATH_DEBUG_ALQ */ sc->sc_stats.ast_tdma_tsf++; } ath_tdma_beacon_send(sc, vap); /* prepare response */ |