Path: blob/main/sys/dev/ath/ath_hal/ar5210/ar5210_beacon.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2004 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"22#include "ah_desc.h"2324#include "ar5210/ar5210.h"25#include "ar5210/ar5210reg.h"26#include "ar5210/ar5210desc.h"2728/*29* Return the hardware NextTBTT in TSF30*/31uint64_t32ar5210GetNextTBTT(struct ath_hal *ah)33{34#define TU_TO_TSF(_tu) (((uint64_t)(_tu)) << 10)35return TU_TO_TSF(OS_REG_READ(ah, AR_TIMER0));36#undef TU_TO_TSF37}3839/*40* Initialize all of the hardware registers used to send beacons.41*/42void43ar5210SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)44{4546OS_REG_WRITE(ah, AR_TIMER0, bt->bt_nexttbtt);47OS_REG_WRITE(ah, AR_TIMER1, bt->bt_nextdba);48OS_REG_WRITE(ah, AR_TIMER2, bt->bt_nextswba);49OS_REG_WRITE(ah, AR_TIMER3, bt->bt_nextatim);50/*51* Set the Beacon register after setting all timers.52*/53OS_REG_WRITE(ah, AR_BEACON, bt->bt_intval);54}5556/*57* Legacy api to Initialize all of the beacon registers.58*/59void60ar5210BeaconInit(struct ath_hal *ah,61uint32_t next_beacon, uint32_t beacon_period)62{63HAL_BEACON_TIMERS bt;6465bt.bt_nexttbtt = next_beacon;6667if (AH_PRIVATE(ah)->ah_opmode != HAL_M_STA) {68bt.bt_nextdba = (next_beacon -69ah->ah_config.ah_dma_beacon_response_time) << 3; /* 1/8 TU */70bt.bt_nextswba = (next_beacon -71ah->ah_config.ah_sw_beacon_response_time) << 3; /* 1/8 TU */72/*73* The SWBA interrupt is not used for beacons in ad hoc mode74* as we don't yet support ATIMs. So since the beacon never75* changes, the beacon descriptor is set up once and read76* into a special HW buffer, from which it will be77* automagically retrieved at each DMA Beacon Alert (DBA).78*/7980/* Set the ATIM window */81bt.bt_nextatim = next_beacon + 0; /* NB: no ATIMs */82} else {83bt.bt_nextdba = ~0;84bt.bt_nextswba = ~0;85bt.bt_nextatim = 1;86}87bt.bt_intval = beacon_period &88(AR_BEACON_PERIOD | AR_BEACON_RESET_TSF | AR_BEACON_EN);89ar5210SetBeaconTimers(ah, &bt);90}9192void93ar5210ResetStaBeaconTimers(struct ath_hal *ah)94{95uint32_t val;9697OS_REG_WRITE(ah, AR_TIMER0, 0); /* no beacons */98val = OS_REG_READ(ah, AR_STA_ID1);99val |= AR_STA_ID1_NO_PSPOLL; /* XXX */100/* tell the h/w that the associated AP is not PCF capable */101OS_REG_WRITE(ah, AR_STA_ID1,102val & ~(AR_STA_ID1_DEFAULT_ANTENNA | AR_STA_ID1_PCF));103OS_REG_WRITE(ah, AR_BEACON, AR_BEACON_PERIOD);104}105106/*107* Set all the beacon related bits on the h/w for stations108* i.e. initializes the corresponding h/w timers;109* also tells the h/w whether to anticipate PCF beacons110*111* dtim_count and cfp_count from the current beacon - their current112* values aren't necessarily maintained in the device struct113*/114void115ar5210SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)116{117struct ath_hal_5210 *ahp = AH5210(ah);118119HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: setting beacon timers\n", __func__);120121HALASSERT(bs->bs_intval != 0);122/* if the AP will do PCF */123if (bs->bs_cfpmaxduration != 0) {124/* tell the h/w that the associated AP is PCF capable */125OS_REG_WRITE(ah, AR_STA_ID1,126(OS_REG_READ(ah, AR_STA_ID1) &~ AR_STA_ID1_DEFAULT_ANTENNA)127| AR_STA_ID1_PCF);128129/* set CFP_PERIOD(1.024ms) register */130OS_REG_WRITE(ah, AR_CFP_PERIOD, bs->bs_cfpperiod);131132/* set CFP_DUR(1.024ms) register to max cfp duration */133OS_REG_WRITE(ah, AR_CFP_DUR, bs->bs_cfpmaxduration);134135/* set TIMER2(128us) to anticipated time of next CFP */136OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);137} else {138/* tell the h/w that the associated AP is not PCF capable */139OS_REG_WRITE(ah, AR_STA_ID1,140OS_REG_READ(ah, AR_STA_ID1) &~ (AR_STA_ID1_DEFAULT_ANTENNA | AR_STA_ID1_PCF));141}142143/*144* Set TIMER0(1.024ms) to the anticipated time of the next beacon.145*/146OS_REG_WRITE(ah, AR_TIMER0, bs->bs_nexttbtt);147148/*149* Start the beacon timers by setting the BEACON register150* to the beacon interval; also write the tim offset which151* we should know by now. The code, in ar5211WriteAssocid,152* also sets the tim offset once the AID is known which can153* be left as such for now.154*/155OS_REG_WRITE(ah, AR_BEACON,156(OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_PERIOD|AR_BEACON_TIM))157| SM(bs->bs_intval, AR_BEACON_PERIOD)158| SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)159);160161/*162* Configure the BMISS interrupt. Note that we163* assume the caller blocks interrupts while enabling164* the threshold.165*/166167/*168* Interrupt works only on Crete.169*/170if (AH_PRIVATE(ah)->ah_macRev < AR_SREV_CRETE)171return;172/*173* Counter is only 3-bits.174* Count of 0 with BMISS interrupt enabled will hang the system175* with too many interrupts176*/177if (AH_PRIVATE(ah)->ah_macRev >= AR_SREV_CRETE &&178(bs->bs_bmissthreshold&7) == 0) {179#ifdef AH_DEBUG180ath_hal_printf(ah, "%s: invalid beacon miss threshold %u\n",181__func__, bs->bs_bmissthreshold);182#endif183return;184}185#define BMISS_MAX (AR_RSSI_THR_BM_THR >> AR_RSSI_THR_BM_THR_S)186/*187* Configure the BMISS interrupt. Note that we188* assume the caller blocks interrupts while enabling189* the threshold.190*191* NB: the beacon miss count field is only 3 bits which192* is much smaller than what's found on later parts;193* clamp overflow values as a safeguard.194*/195ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)196| SM(bs->bs_bmissthreshold > BMISS_MAX ?197BMISS_MAX : bs->bs_bmissthreshold,198AR_RSSI_THR_BM_THR);199OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);200#undef BMISS_MAX201}202203204