Path: blob/main/sys/dev/ath/ath_hal/ar5212/ar5212_beacon.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 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 "ar5212/ar5212.h"24#include "ar5212/ar5212reg.h"25#include "ar5212/ar5212desc.h"2627/*28* Return the hardware NextTBTT in TSF29*/30uint64_t31ar5212GetNextTBTT(struct ath_hal *ah)32{33#define TU_TO_TSF(_tu) (((uint64_t)(_tu)) << 10)34return TU_TO_TSF(OS_REG_READ(ah, AR_TIMER0));35#undef TU_TO_TSF36}3738/*39* Initialize all of the hardware registers used to40* send beacons. Note that for station operation the41* driver calls ar5212SetStaBeaconTimers instead.42*/43void44ar5212SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)45{46struct ath_hal_5212 *ahp = AH5212(ah);4748/*49* Limit the timers to their specific resolutions:50*51* + Timer 0 - 0..15 0xffff TU52* + Timer 1 - 0..18 0x7ffff TU/853* + Timer 2 - 0..24 0x1ffffff TU/854* + Timer 3 - 0..15 0xffff TU55*/56OS_REG_WRITE(ah, AR_TIMER0, bt->bt_nexttbtt & 0xffff);57OS_REG_WRITE(ah, AR_TIMER1, bt->bt_nextdba & 0x7ffff);58OS_REG_WRITE(ah, AR_TIMER2, bt->bt_nextswba & 0x1ffffff);59/* XXX force nextatim to be non-zero? */60OS_REG_WRITE(ah, AR_TIMER3, bt->bt_nextatim & 0xffff);61/*62* Set the Beacon register after setting all timers.63*/64if (bt->bt_intval & AR_BEACON_RESET_TSF) {65/*66* When resetting the TSF,67* write twice to the corresponding register; each68* write to the RESET_TSF bit toggles the internal69* signal to cause a reset of the TSF - but if the signal70* is left high, it will reset the TSF on the next71* chip reset also! writing the bit an even number72* of times fixes this issue73*/74OS_REG_WRITE(ah, AR_BEACON, AR_BEACON_RESET_TSF);75}76OS_REG_WRITE(ah, AR_BEACON, bt->bt_intval);77ahp->ah_beaconInterval = (bt->bt_intval & HAL_BEACON_PERIOD);78}7980/*81* Old api for setting up beacon timer registers when82* operating in !station mode. Note the fixed constants83* adjusting the DBA and SWBA timers and the fixed ATIM84* window.85*/86void87ar5212BeaconInit(struct ath_hal *ah,88uint32_t next_beacon, uint32_t beacon_period)89{90HAL_BEACON_TIMERS bt;9192bt.bt_nexttbtt = next_beacon;93/*94* TIMER1: in AP/adhoc mode this controls the DMA beacon95* alert timer; otherwise it controls the next wakeup time.96* TIMER2: in AP mode, it controls the SBA beacon alert97* interrupt; otherwise it sets the start of the next CFP.98*/99switch (AH_PRIVATE(ah)->ah_opmode) {100case HAL_M_STA:101case HAL_M_MONITOR:102bt.bt_nextdba = 0xffff;103bt.bt_nextswba = 0x7ffff;104break;105case HAL_M_HOSTAP:106case HAL_M_IBSS:107bt.bt_nextdba = (next_beacon -108ah->ah_config.ah_dma_beacon_response_time) << 3; /* 1/8 TU */109bt.bt_nextswba = (next_beacon -110ah->ah_config.ah_sw_beacon_response_time) << 3; /* 1/8 TU */111break;112}113/*114* Set the ATIM window115* Our hardware does not support an ATIM window of 0116* (beacons will not work). If the ATIM windows is 0,117* force it to 1.118*/119bt.bt_nextatim = next_beacon + 1;120bt.bt_intval = beacon_period &121(AR_BEACON_PERIOD | AR_BEACON_RESET_TSF | AR_BEACON_EN);122ar5212SetBeaconTimers(ah, &bt);123}124125void126ar5212ResetStaBeaconTimers(struct ath_hal *ah)127{128uint32_t val;129130OS_REG_WRITE(ah, AR_TIMER0, 0); /* no beacons */131val = OS_REG_READ(ah, AR_STA_ID1);132val |= AR_STA_ID1_PWR_SAV; /* XXX */133/* tell the h/w that the associated AP is not PCF capable */134OS_REG_WRITE(ah, AR_STA_ID1,135val & ~(AR_STA_ID1_USE_DEFANT | AR_STA_ID1_PCF));136OS_REG_WRITE(ah, AR_BEACON, AR_BEACON_PERIOD);137}138139/*140* Set all the beacon related bits on the h/w for stations141* i.e. initializes the corresponding h/w timers;142* also tells the h/w whether to anticipate PCF beacons143*/144void145ar5212SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)146{147struct ath_hal_5212 *ahp = AH5212(ah);148uint32_t nextTbtt, nextdtim,beaconintval, dtimperiod;149150HALASSERT(bs->bs_intval != 0);151/* if the AP will do PCF */152if (bs->bs_cfpmaxduration != 0) {153/* tell the h/w that the associated AP is PCF capable */154OS_REG_WRITE(ah, AR_STA_ID1,155OS_REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PCF);156157/* set CFP_PERIOD(1.024ms) register */158OS_REG_WRITE(ah, AR_CFP_PERIOD, bs->bs_cfpperiod);159160/* set CFP_DUR(1.024ms) register to max cfp duration */161OS_REG_WRITE(ah, AR_CFP_DUR, bs->bs_cfpmaxduration);162163/* set TIMER2(128us) to anticipated time of next CFP */164OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);165} else {166/* tell the h/w that the associated AP is not PCF capable */167OS_REG_WRITE(ah, AR_STA_ID1,168OS_REG_READ(ah, AR_STA_ID1) &~ AR_STA_ID1_PCF);169}170171/*172* Set TIMER0(1.024ms) to the anticipated time of the next beacon.173*/174OS_REG_WRITE(ah, AR_TIMER0, bs->bs_nexttbtt);175176/*177* Start the beacon timers by setting the BEACON register178* to the beacon interval; also write the tim offset which179* we should know by now. The code, in ar5211WriteAssocid,180* also sets the tim offset once the AID is known which can181* be left as such for now.182*/183OS_REG_WRITE(ah, AR_BEACON,184(OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_PERIOD|AR_BEACON_TIM))185| SM(bs->bs_intval, AR_BEACON_PERIOD)186| SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)187);188189/*190* Configure the BMISS interrupt. Note that we191* assume the caller blocks interrupts while enabling192* the threshold.193*/194HALASSERT(bs->bs_bmissthreshold <= MS(0xffffffff, AR_RSSI_THR_BM_THR));195ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)196| SM(bs->bs_bmissthreshold, AR_RSSI_THR_BM_THR);197OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);198199/*200* Program the sleep registers to correlate with the beacon setup.201*/202203/*204* Oahu beacons timers on the station were used for power205* save operation (waking up in anticipation of a beacon)206* and any CFP function; Venice does sleep/power-save timers207* differently - so this is the right place to set them up;208* don't think the beacon timers are used by venice sta hw209* for any useful purpose anymore210* Setup venice's sleep related timers211* Current implementation assumes sw processing of beacons -212* assuming an interrupt is generated every beacon which213* causes the hardware to become awake until the sw tells214* it to go to sleep again; beacon timeout is to allow for215* beacon jitter; cab timeout is max time to wait for cab216* after seeing the last DTIM or MORE CAB bit217*/218#define CAB_TIMEOUT_VAL 10 /* in TU */219#define BEACON_TIMEOUT_VAL 10 /* in TU */220#define SLEEP_SLOP 3 /* in TU */221222/*223* For max powersave mode we may want to sleep for longer than a224* beacon period and not want to receive all beacons; modify the225* timers accordingly; make sure to align the next TIM to the226* next DTIM if we decide to wake for DTIMs only227*/228beaconintval = bs->bs_intval & HAL_BEACON_PERIOD;229HALASSERT(beaconintval != 0);230if (bs->bs_sleepduration > beaconintval) {231HALASSERT(roundup(bs->bs_sleepduration, beaconintval) ==232bs->bs_sleepduration);233beaconintval = bs->bs_sleepduration;234}235dtimperiod = bs->bs_dtimperiod;236if (bs->bs_sleepduration > dtimperiod) {237HALASSERT(dtimperiod == 0 ||238roundup(bs->bs_sleepduration, dtimperiod) ==239bs->bs_sleepduration);240dtimperiod = bs->bs_sleepduration;241}242HALASSERT(beaconintval <= dtimperiod);243if (beaconintval == dtimperiod)244nextTbtt = bs->bs_nextdtim;245else246nextTbtt = bs->bs_nexttbtt;247nextdtim = bs->bs_nextdtim;248249OS_REG_WRITE(ah, AR_SLEEP1,250SM((nextdtim - SLEEP_SLOP) << 3, AR_SLEEP1_NEXT_DTIM)251| SM(CAB_TIMEOUT_VAL, AR_SLEEP1_CAB_TIMEOUT)252| AR_SLEEP1_ASSUME_DTIM253| AR_SLEEP1_ENH_SLEEP_ENA254);255OS_REG_WRITE(ah, AR_SLEEP2,256SM((nextTbtt - SLEEP_SLOP) << 3, AR_SLEEP2_NEXT_TIM)257| SM(BEACON_TIMEOUT_VAL, AR_SLEEP2_BEACON_TIMEOUT)258);259OS_REG_WRITE(ah, AR_SLEEP3,260SM(beaconintval, AR_SLEEP3_TIM_PERIOD)261| SM(dtimperiod, AR_SLEEP3_DTIM_PERIOD)262);263HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: next DTIM %d\n",264__func__, bs->bs_nextdtim);265HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: next beacon %d\n",266__func__, nextTbtt);267HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: beacon period %d\n",268__func__, beaconintval);269HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: DTIM period %d\n",270__func__, dtimperiod);271#undef CAB_TIMEOUT_VAL272#undef BEACON_TIMEOUT_VAL273#undef SLEEP_SLOP274}275276277