summaryrefslogtreecommitdiffstats
path: root/sys/dev/ath/if_ath_beacon.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/ath/if_ath_beacon.c')
-rw-r--r--sys/dev/ath/if_ath_beacon.c93
1 files changed, 81 insertions, 12 deletions
diff --git a/sys/dev/ath/if_ath_beacon.c b/sys/dev/ath/if_ath_beacon.c
index 11b0426..a672c71 100644
--- a/sys/dev/ath/if_ath_beacon.c
+++ b/sys/dev/ath/if_ath_beacon.c
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <net/if.h>
+#include <net/if_var.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
@@ -381,7 +382,7 @@ ath_beacon_update(struct ieee80211vap *vap, int item)
/*
* Handle a beacon miss.
*/
-static void
+void
ath_beacon_miss(struct ath_softc *sc)
{
HAL_SURVEY_SAMPLE hs;
@@ -748,6 +749,11 @@ ath_beacon_generate(struct ath_softc *sc, struct ieee80211vap *vap)
*
* More thought is required here.
*/
+ /*
+ * XXX can we even stop TX DMA here? Check what the
+ * reference driver does for cabq for beacons, given
+ * that stopping TX requires RX is paused.
+ */
ath_tx_draintxq(sc, cabq);
}
}
@@ -915,7 +921,7 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
struct ieee80211_node *ni;
u_int32_t nexttbtt, intval, tsftu;
u_int32_t nexttbtt_u8, intval_u8;
- u_int64_t tsf;
+ u_int64_t tsf, tsf_beacon;
if (vap == NULL)
vap = TAILQ_FIRST(&ic->ic_vaps); /* XXX */
@@ -931,9 +937,17 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
ni = ieee80211_ref_node(vap->iv_bss);
+ ATH_LOCK(sc);
+ ath_power_set_power_state(sc, HAL_PM_AWAKE);
+ ATH_UNLOCK(sc);
+
/* extract tstamp from last beacon and convert to TU */
nexttbtt = TSF_TO_TU(LE_READ_4(ni->ni_tstamp.data + 4),
LE_READ_4(ni->ni_tstamp.data));
+
+ tsf_beacon = ((uint64_t) LE_READ_4(ni->ni_tstamp.data + 4)) << 32;
+ tsf_beacon |= LE_READ_4(ni->ni_tstamp.data);
+
if (ic->ic_opmode == IEEE80211_M_HOSTAP ||
ic->ic_opmode == IEEE80211_M_MBSS) {
/*
@@ -979,14 +993,63 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
*/
tsf = ath_hal_gettsf64(ah);
tsftu = TSF_TO_TU(tsf>>32, tsf) + FUDGE;
- do {
- nexttbtt += intval;
- if (--dtimcount < 0) {
- dtimcount = dtimperiod - 1;
- if (--cfpcount < 0)
- cfpcount = cfpperiod - 1;
+
+ DPRINTF(sc, ATH_DEBUG_BEACON,
+ "%s: beacon tsf=%llu, hw tsf=%llu, nexttbtt=%u, tsftu=%u\n",
+ __func__,
+ (unsigned long long) tsf_beacon,
+ (unsigned long long) tsf,
+ nexttbtt,
+ tsftu);
+ DPRINTF(sc, ATH_DEBUG_BEACON,
+ "%s: beacon tsf=%llu, hw tsf=%llu, tsf delta=%lld\n",
+ __func__,
+ (unsigned long long) tsf_beacon,
+ (unsigned long long) tsf,
+ (long long) tsf -
+ (long long) tsf_beacon);
+
+ DPRINTF(sc, ATH_DEBUG_BEACON,
+ "%s: nexttbtt=%llu, beacon tsf delta=%lld\n",
+ __func__,
+ (unsigned long long) nexttbtt,
+ (long long) ((long long) nexttbtt * 1024LL) - (long long) tsf_beacon);
+
+ /* XXX cfpcount? */
+
+ if (nexttbtt > tsftu) {
+ uint32_t countdiff, oldtbtt, remainder;
+
+ oldtbtt = nexttbtt;
+ remainder = (nexttbtt - tsftu) % intval;
+ nexttbtt = tsftu + remainder;
+
+ countdiff = (oldtbtt - nexttbtt) / intval % dtimperiod;
+ if (dtimcount > countdiff) {
+ dtimcount -= countdiff;
+ } else {
+ dtimcount += dtimperiod - countdiff;
+ }
+ } else { //nexttbtt <= tsftu
+ uint32_t countdiff, oldtbtt, remainder;
+
+ oldtbtt = nexttbtt;
+ remainder = (tsftu - nexttbtt) % intval;
+ nexttbtt = tsftu - remainder + intval;
+ countdiff = (nexttbtt - oldtbtt) / intval % dtimperiod;
+ if (dtimcount > countdiff) {
+ dtimcount -= countdiff;
+ } else {
+ dtimcount += dtimperiod - countdiff;
}
- } while (nexttbtt < tsftu);
+ }
+
+ DPRINTF(sc, ATH_DEBUG_BEACON,
+ "%s: adj nexttbtt=%llu, rx tsf delta=%lld\n",
+ __func__,
+ (unsigned long long) nexttbtt,
+ (long long) ((long long)nexttbtt * 1024LL) - (long long)tsf);
+
memset(&bs, 0, sizeof(bs));
bs.bs_intval = intval;
bs.bs_nexttbtt = nexttbtt;
@@ -1033,9 +1096,12 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
bs.bs_sleepduration = roundup(bs.bs_sleepduration, bs.bs_dtimperiod);
DPRINTF(sc, ATH_DEBUG_BEACON,
- "%s: tsf %ju tsf:tu %u intval %u nexttbtt %u dtim %u nextdtim %u bmiss %u sleep %u cfp:period %u maxdur %u next %u timoffset %u\n"
+ "%s: tsf %ju tsf:tu %u intval %u nexttbtt %u dtim %u "
+ "nextdtim %u bmiss %u sleep %u cfp:period %u "
+ "maxdur %u next %u timoffset %u\n"
, __func__
- , tsf, tsftu
+ , tsf
+ , tsftu
, bs.bs_intval
, bs.bs_nexttbtt
, bs.bs_dtimperiod
@@ -1112,8 +1178,11 @@ ath_beacon_config(struct ath_softc *sc, struct ieee80211vap *vap)
if (ic->ic_opmode == IEEE80211_M_IBSS && sc->sc_hasveol)
ath_beacon_start_adhoc(sc, vap);
}
- sc->sc_syncbeacon = 0;
ieee80211_free_node(ni);
+
+ ATH_LOCK(sc);
+ ath_power_restore_power_state(sc);
+ ATH_UNLOCK(sc);
#undef FUDGE
#undef TSF_TO_TU
}
OpenPOWER on IntegriCloud