FreeBSD kernel ATH device code
ar5212_beacon.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: ISC
3 *
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $FreeBSD$
20 */
21#include "opt_ah.h"
22
23#include "ah.h"
24#include "ah_internal.h"
25
26#include "ar5212/ar5212.h"
27#include "ar5212/ar5212reg.h"
28#include "ar5212/ar5212desc.h"
29
30/*
31 * Return the hardware NextTBTT in TSF
32 */
33uint64_t
35{
36#define TU_TO_TSF(_tu) (((uint64_t)(_tu)) << 10)
37 return TU_TO_TSF(OS_REG_READ(ah, AR_TIMER0));
38#undef TU_TO_TSF
39}
40
41/*
42 * Initialize all of the hardware registers used to
43 * send beacons. Note that for station operation the
44 * driver calls ar5212SetStaBeaconTimers instead.
45 */
46void
48{
49 struct ath_hal_5212 *ahp = AH5212(ah);
50
51 /*
52 * Limit the timers to their specific resolutions:
53 *
54 * + Timer 0 - 0..15 0xffff TU
55 * + Timer 1 - 0..18 0x7ffff TU/8
56 * + Timer 2 - 0..24 0x1ffffff TU/8
57 * + Timer 3 - 0..15 0xffff TU
58 */
59 OS_REG_WRITE(ah, AR_TIMER0, bt->bt_nexttbtt & 0xffff);
60 OS_REG_WRITE(ah, AR_TIMER1, bt->bt_nextdba & 0x7ffff);
61 OS_REG_WRITE(ah, AR_TIMER2, bt->bt_nextswba & 0x1ffffff);
62 /* XXX force nextatim to be non-zero? */
63 OS_REG_WRITE(ah, AR_TIMER3, bt->bt_nextatim & 0xffff);
64 /*
65 * Set the Beacon register after setting all timers.
66 */
68 /*
69 * When resetting the TSF,
70 * write twice to the corresponding register; each
71 * write to the RESET_TSF bit toggles the internal
72 * signal to cause a reset of the TSF - but if the signal
73 * is left high, it will reset the TSF on the next
74 * chip reset also! writing the bit an even number
75 * of times fixes this issue
76 */
78 }
81}
82
83/*
84 * Old api for setting up beacon timer registers when
85 * operating in !station mode. Note the fixed constants
86 * adjusting the DBA and SWBA timers and the fixed ATIM
87 * window.
88 */
89void
91 uint32_t next_beacon, uint32_t beacon_period)
92{
94
95 bt.bt_nexttbtt = next_beacon;
96 /*
97 * TIMER1: in AP/adhoc mode this controls the DMA beacon
98 * alert timer; otherwise it controls the next wakeup time.
99 * TIMER2: in AP mode, it controls the SBA beacon alert
100 * interrupt; otherwise it sets the start of the next CFP.
101 */
102 switch (AH_PRIVATE(ah)->ah_opmode) {
103 case HAL_M_STA:
104 case HAL_M_MONITOR:
105 bt.bt_nextdba = 0xffff;
106 bt.bt_nextswba = 0x7ffff;
107 break;
108 case HAL_M_HOSTAP:
109 case HAL_M_IBSS:
110 bt.bt_nextdba = (next_beacon -
111 ah->ah_config.ah_dma_beacon_response_time) << 3; /* 1/8 TU */
112 bt.bt_nextswba = (next_beacon -
113 ah->ah_config.ah_sw_beacon_response_time) << 3; /* 1/8 TU */
114 break;
115 }
116 /*
117 * Set the ATIM window
118 * Our hardware does not support an ATIM window of 0
119 * (beacons will not work). If the ATIM windows is 0,
120 * force it to 1.
121 */
122 bt.bt_nextatim = next_beacon + 1;
123 bt.bt_intval = beacon_period &
125 ar5212SetBeaconTimers(ah, &bt);
126}
127
128void
130{
131 uint32_t val;
132
133 OS_REG_WRITE(ah, AR_TIMER0, 0); /* no beacons */
134 val = OS_REG_READ(ah, AR_STA_ID1);
135 val |= AR_STA_ID1_PWR_SAV; /* XXX */
136 /* tell the h/w that the associated AP is not PCF capable */
140}
141
142/*
143 * Set all the beacon related bits on the h/w for stations
144 * i.e. initializes the corresponding h/w timers;
145 * also tells the h/w whether to anticipate PCF beacons
146 */
147void
149{
150 struct ath_hal_5212 *ahp = AH5212(ah);
151 uint32_t nextTbtt, nextdtim,beaconintval, dtimperiod;
152
153 HALASSERT(bs->bs_intval != 0);
154 /* if the AP will do PCF */
155 if (bs->bs_cfpmaxduration != 0) {
156 /* tell the h/w that the associated AP is PCF capable */
159
160 /* set CFP_PERIOD(1.024ms) register */
162
163 /* set CFP_DUR(1.024ms) register to max cfp duration */
165
166 /* set TIMER2(128us) to anticipated time of next CFP */
167 OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);
168 } else {
169 /* tell the h/w that the associated AP is not PCF capable */
172 }
173
174 /*
175 * Set TIMER0(1.024ms) to the anticipated time of the next beacon.
176 */
178
179 /*
180 * Start the beacon timers by setting the BEACON register
181 * to the beacon interval; also write the tim offset which
182 * we should know by now. The code, in ar5211WriteAssocid,
183 * also sets the tim offset once the AID is known which can
184 * be left as such for now.
185 */
189 | SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)
190 );
191
192 /*
193 * Configure the BMISS interrupt. Note that we
194 * assume the caller blocks interrupts while enabling
195 * the threshold.
196 */
198 ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)
201
202 /*
203 * Program the sleep registers to correlate with the beacon setup.
204 */
205
206 /*
207 * Oahu beacons timers on the station were used for power
208 * save operation (waking up in anticipation of a beacon)
209 * and any CFP function; Venice does sleep/power-save timers
210 * differently - so this is the right place to set them up;
211 * don't think the beacon timers are used by venice sta hw
212 * for any useful purpose anymore
213 * Setup venice's sleep related timers
214 * Current implementation assumes sw processing of beacons -
215 * assuming an interrupt is generated every beacon which
216 * causes the hardware to become awake until the sw tells
217 * it to go to sleep again; beacon timeout is to allow for
218 * beacon jitter; cab timeout is max time to wait for cab
219 * after seeing the last DTIM or MORE CAB bit
220 */
221#define CAB_TIMEOUT_VAL 10 /* in TU */
222#define BEACON_TIMEOUT_VAL 10 /* in TU */
223#define SLEEP_SLOP 3 /* in TU */
224
225 /*
226 * For max powersave mode we may want to sleep for longer than a
227 * beacon period and not want to receive all beacons; modify the
228 * timers accordingly; make sure to align the next TIM to the
229 * next DTIM if we decide to wake for DTIMs only
230 */
231 beaconintval = bs->bs_intval & HAL_BEACON_PERIOD;
232 HALASSERT(beaconintval != 0);
233 if (bs->bs_sleepduration > beaconintval) {
234 HALASSERT(roundup(bs->bs_sleepduration, beaconintval) ==
235 bs->bs_sleepduration);
236 beaconintval = bs->bs_sleepduration;
237 }
238 dtimperiod = bs->bs_dtimperiod;
239 if (bs->bs_sleepduration > dtimperiod) {
240 HALASSERT(dtimperiod == 0 ||
241 roundup(bs->bs_sleepduration, dtimperiod) ==
242 bs->bs_sleepduration);
243 dtimperiod = bs->bs_sleepduration;
244 }
245 HALASSERT(beaconintval <= dtimperiod);
246 if (beaconintval == dtimperiod)
247 nextTbtt = bs->bs_nextdtim;
248 else
249 nextTbtt = bs->bs_nexttbtt;
250 nextdtim = bs->bs_nextdtim;
251
253 SM((nextdtim - SLEEP_SLOP) << 3, AR_SLEEP1_NEXT_DTIM)
257 );
259 SM((nextTbtt - SLEEP_SLOP) << 3, AR_SLEEP2_NEXT_TIM)
261 );
263 SM(beaconintval, AR_SLEEP3_TIM_PERIOD)
264 | SM(dtimperiod, AR_SLEEP3_DTIM_PERIOD)
265 );
266 HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: next DTIM %d\n",
267 __func__, bs->bs_nextdtim);
268 HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: next beacon %d\n",
269 __func__, nextTbtt);
270 HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: beacon period %d\n",
271 __func__, beaconintval);
272 HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: DTIM period %d\n",
273 __func__, dtimperiod);
274#undef CAB_TIMEOUT_VAL
275#undef BEACON_TIMEOUT_VAL
276#undef SLEEP_SLOP
277}
#define HAL_BEACON_PERIOD
Definition: ah.h:837
@ HAL_M_IBSS
Definition: ah.h:766
@ HAL_M_MONITOR
Definition: ah.h:768
@ HAL_M_STA
Definition: ah.h:765
@ HAL_M_HOSTAP
Definition: ah.h:767
@ HAL_DEBUG_BEACON
Definition: ah_debug.h:45
#define SM(_v, _f)
Definition: ah_internal.h:587
#define MS(_v, _f)
Definition: ah_internal.h:588
#define AH_PRIVATE(_ah)
Definition: ah_internal.h:442
#define HALASSERT(_x)
Definition: ah_internal.h:683
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
#define roundup(x, y)
Definition: ah_internal.h:40
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AR_BEACON_PERIOD
Definition: ar5210reg.h:348
#define AR_BEACON
Definition: ar5210reg.h:79
#define AR_STA_ID1
Definition: ar5210reg.h:71
#define AR_TIMER0
Definition: ar5210reg.h:81
#define AR_STA_ID1_PCF
Definition: ar5210reg.h:309
#define AR_TIMER1
Definition: ar5210reg.h:82
#define AR_BEACON_TIM
Definition: ar5210reg.h:350
#define AR_TIMER3
Definition: ar5210reg.h:84
#define AR_TIMER2
Definition: ar5210reg.h:83
#define AR_BEACON_EN
Definition: ar5210reg.h:352
#define AR_CFP_PERIOD
Definition: ar5210reg.h:80
#define AR_BEACON_RESET_TSF
Definition: ar5210reg.h:353
#define AR_CFP_DUR
Definition: ar5210reg.h:87
#define AR_RSSI_THR
Definition: ar5210reg.h:76
#define AR_RSSI_THR_BM_THR
Definition: ar5210reg.h:325
#define AR_STA_ID1_PWR_SAV
Definition: ar5211reg.h:763
#define AH5212(_ah)
Definition: ar5212.h:354
#define TU_TO_TSF(_tu)
#define BEACON_TIMEOUT_VAL
void ar5212ResetStaBeaconTimers(struct ath_hal *ah)
void ar5212SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)
Definition: ar5212_beacon.c:47
#define SLEEP_SLOP
void ar5212SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)
uint64_t ar5212GetNextTBTT(struct ath_hal *ah)
Definition: ar5212_beacon.c:34
#define CAB_TIMEOUT_VAL
void ar5212BeaconInit(struct ath_hal *ah, uint32_t next_beacon, uint32_t beacon_period)
Definition: ar5212_beacon.c:90
#define AR_SLEEP1_CAB_TIMEOUT
Definition: ar5212reg.h:926
#define AR_SLEEP1_ENH_SLEEP_ENA
Definition: ar5212reg.h:925
#define AR_SLEEP3_DTIM_PERIOD
Definition: ar5212reg.h:936
#define AR_SLEEP1_NEXT_DTIM
Definition: ar5212reg.h:922
#define AR_SLEEP3
Definition: ar5212reg.h:293
#define AR_SLEEP2_BEACON_TIMEOUT
Definition: ar5212reg.h:931
#define AR_STA_ID1_USE_DEFANT
Definition: ar5212reg.h:850
#define AR_SLEEP1_ASSUME_DTIM
Definition: ar5212reg.h:924
#define AR_SLEEP2
Definition: ar5212reg.h:292
#define AR_SLEEP3_TIM_PERIOD
Definition: ar5212reg.h:934
#define AR_SLEEP2_NEXT_TIM
Definition: ar5212reg.h:929
#define AR_SLEEP1
Definition: ar5212reg.h:291
uint16_t bs_cfpmaxduration
Definition: ah.h:844
uint32_t bs_sleepduration
Definition: ah.h:848
uint16_t bs_timoffset
Definition: ah.h:846
uint16_t bs_cfpperiod
Definition: ah.h:843
uint32_t bs_dtimperiod
Definition: ah.h:842
uint32_t bs_intval
Definition: ah.h:831
uint16_t bs_bmissthreshold
Definition: ah.h:847
uint32_t bs_nexttbtt
Definition: ah.h:829
uint32_t bs_cfpnext
Definition: ah.h:845
uint32_t bs_nextdtim
Definition: ah.h:830
uint32_t bt_nextatim
Definition: ah.h:859
uint32_t bt_intval
Definition: ah.h:857
uint32_t bt_nexttbtt
Definition: ah.h:858
uint32_t bt_nextdba
Definition: ah.h:860
uint32_t bt_nextswba
Definition: ah.h:861
int ah_dma_beacon_response_time
Definition: ah.h:1159
int ah_sw_beacon_response_time
Definition: ah.h:1160
uint32_t ah_rssiThr
Definition: ar5212.h:288
uint32_t ah_beaconInterval
Definition: ar5212.h:294
Definition: ah.h:1219
HAL_OPS_CONFIG ah_config
Definition: ah.h:1243