Path: blob/main/sys/dev/ath/ath_hal/ar5211/ar5211_beacon.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2006 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"2223#include "ar5211/ar5211.h"24#include "ar5211/ar5211reg.h"25#include "ar5211/ar5211desc.h"2627/*28* Routines used to initialize and generated beacons for the AR5211/AR5311.29*/3031/*32* Return the hardware NextTBTT in TSF33*/34uint64_t35ar5211GetNextTBTT(struct ath_hal *ah)36{37#define TU_TO_TSF(_tu) (((uint64_t)(_tu)) << 10)38return TU_TO_TSF(OS_REG_READ(ah, AR_TIMER0));39#undef TU_TO_TSF40}4142/*43* Initialize all of the hardware registers used to send beacons.44*/45void46ar5211SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)47{4849OS_REG_WRITE(ah, AR_TIMER0, bt->bt_nexttbtt);50OS_REG_WRITE(ah, AR_TIMER1, bt->bt_nextdba);51OS_REG_WRITE(ah, AR_TIMER2, bt->bt_nextswba);52OS_REG_WRITE(ah, AR_TIMER3, bt->bt_nextatim);53/*54* Set the Beacon register after setting all timers.55*/56OS_REG_WRITE(ah, AR_BEACON, bt->bt_intval);57}5859/*60* Legacy api to initialize all of the beacon registers.61*/62void63ar5211BeaconInit(struct ath_hal *ah,64uint32_t next_beacon, uint32_t beacon_period)65{66HAL_BEACON_TIMERS bt;6768bt.bt_nexttbtt = next_beacon;69/*70* TIMER1: in AP/adhoc mode this controls the DMA beacon71* alert timer; otherwise it controls the next wakeup time.72* TIMER2: in AP mode, it controls the SBA beacon alert73* interrupt; otherwise it sets the start of the next CFP.74*/75switch (AH_PRIVATE(ah)->ah_opmode) {76case HAL_M_STA:77case HAL_M_MONITOR:78bt.bt_nextdba = 0xffff;79bt.bt_nextswba = 0x7ffff;80break;81case HAL_M_IBSS:82case HAL_M_HOSTAP:83bt.bt_nextdba = (next_beacon -84ah->ah_config.ah_dma_beacon_response_time) << 3; /* 1/8 TU */85bt.bt_nextswba = (next_beacon -86ah->ah_config.ah_sw_beacon_response_time) << 3; /* 1/8 TU */87break;88}89/*90* Set the ATIM window91* Our hardware does not support an ATIM window of 092* (beacons will not work). If the ATIM windows is 0,93* force it to 1.94*/95bt.bt_nextatim = next_beacon + 1;96bt.bt_intval = beacon_period &97(AR_BEACON_PERIOD | AR_BEACON_RESET_TSF | AR_BEACON_EN);98ar5211SetBeaconTimers(ah, &bt);99}100101void102ar5211ResetStaBeaconTimers(struct ath_hal *ah)103{104uint32_t val;105106OS_REG_WRITE(ah, AR_TIMER0, 0); /* no beacons */107val = OS_REG_READ(ah, AR_STA_ID1);108val |= AR_STA_ID1_PWR_SAV; /* XXX */109/* tell the h/w that the associated AP is not PCF capable */110OS_REG_WRITE(ah, AR_STA_ID1,111val & ~(AR_STA_ID1_DEFAULT_ANTENNA | AR_STA_ID1_PCF));112OS_REG_WRITE(ah, AR_BEACON, AR_BEACON_PERIOD);113}114115/*116* Set all the beacon related bits on the h/w for stations117* i.e. initializes the corresponding h/w timers;118* also tells the h/w whether to anticipate PCF beacons119*/120void121ar5211SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)122{123struct ath_hal_5211 *ahp = AH5211(ah);124125HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: setting beacon timers\n", __func__);126127HALASSERT(bs->bs_intval != 0);128/* if the AP will do PCF */129if (bs->bs_cfpmaxduration != 0) {130/* tell the h/w that the associated AP is PCF capable */131OS_REG_WRITE(ah, AR_STA_ID1,132OS_REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PCF);133134/* set CFP_PERIOD(1.024ms) register */135OS_REG_WRITE(ah, AR_CFP_PERIOD, bs->bs_cfpperiod);136137/* set CFP_DUR(1.024ms) register to max cfp duration */138OS_REG_WRITE(ah, AR_CFP_DUR, bs->bs_cfpmaxduration);139140/* set TIMER2(128us) to anticipated time of next CFP */141OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);142} else {143/* tell the h/w that the associated AP is not PCF capable */144OS_REG_WRITE(ah, AR_STA_ID1,145OS_REG_READ(ah, AR_STA_ID1) &~ AR_STA_ID1_PCF);146}147148/*149* Set TIMER0(1.024ms) to the anticipated time of the next beacon.150*/151OS_REG_WRITE(ah, AR_TIMER0, bs->bs_nexttbtt);152153/*154* Start the beacon timers by setting the BEACON register155* to the beacon interval; also write the tim offset which156* we should know by now. The code, in ar5211WriteAssocid,157* also sets the tim offset once the AID is known which can158* be left as such for now.159*/160OS_REG_WRITE(ah, AR_BEACON,161(OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_PERIOD|AR_BEACON_TIM))162| SM(bs->bs_intval, AR_BEACON_PERIOD)163| SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)164);165166/*167* Configure the BMISS interrupt. Note that we168* assume the caller blocks interrupts while enabling169* the threshold.170*/171HALASSERT(bs->bs_bmissthreshold <= MS(0xffffffff, AR_RSSI_THR_BM_THR));172ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)173| SM(bs->bs_bmissthreshold, AR_RSSI_THR_BM_THR);174OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);175176/*177* Set the sleep duration in 1/8 TU's.178*/179#define SLEEP_SLOP 3180OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLDUR,181(bs->bs_sleepduration - SLEEP_SLOP) << 3);182#undef SLEEP_SLOP183}184185186