FreeBSD kernel ATH device code
ar5210_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-2004 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#include "ah_desc.h"
26
27#include "ar5210/ar5210.h"
28#include "ar5210/ar5210reg.h"
29#include "ar5210/ar5210desc.h"
30
31/*
32 * Return the hardware NextTBTT in TSF
33 */
34uint64_t
36{
37#define TU_TO_TSF(_tu) (((uint64_t)(_tu)) << 10)
38 return TU_TO_TSF(OS_REG_READ(ah, AR_TIMER0));
39#undef TU_TO_TSF
40}
41
42/*
43 * Initialize all of the hardware registers used to send beacons.
44 */
45void
47{
48
53 /*
54 * Set the Beacon register after setting all timers.
55 */
57}
58
59/*
60 * Legacy api to Initialize all of the beacon registers.
61 */
62void
64 uint32_t next_beacon, uint32_t beacon_period)
65{
67
68 bt.bt_nexttbtt = next_beacon;
69
70 if (AH_PRIVATE(ah)->ah_opmode != HAL_M_STA) {
71 bt.bt_nextdba = (next_beacon -
72 ah->ah_config.ah_dma_beacon_response_time) << 3; /* 1/8 TU */
73 bt.bt_nextswba = (next_beacon -
74 ah->ah_config.ah_sw_beacon_response_time) << 3; /* 1/8 TU */
75 /*
76 * The SWBA interrupt is not used for beacons in ad hoc mode
77 * as we don't yet support ATIMs. So since the beacon never
78 * changes, the beacon descriptor is set up once and read
79 * into a special HW buffer, from which it will be
80 * automagically retrieved at each DMA Beacon Alert (DBA).
81 */
82
83 /* Set the ATIM window */
84 bt.bt_nextatim = next_beacon + 0; /* NB: no ATIMs */
85 } else {
86 bt.bt_nextdba = ~0;
87 bt.bt_nextswba = ~0;
88 bt.bt_nextatim = 1;
89 }
90 bt.bt_intval = beacon_period &
92 ar5210SetBeaconTimers(ah, &bt);
93}
94
95void
97{
98 uint32_t val;
99
100 OS_REG_WRITE(ah, AR_TIMER0, 0); /* no beacons */
101 val = OS_REG_READ(ah, AR_STA_ID1);
102 val |= AR_STA_ID1_NO_PSPOLL; /* XXX */
103 /* tell the h/w that the associated AP is not PCF capable */
107}
108
109/*
110 * Set all the beacon related bits on the h/w for stations
111 * i.e. initializes the corresponding h/w timers;
112 * also tells the h/w whether to anticipate PCF beacons
113 *
114 * dtim_count and cfp_count from the current beacon - their current
115 * values aren't necessarily maintained in the device struct
116 */
117void
119{
120 struct ath_hal_5210 *ahp = AH5210(ah);
121
122 HALDEBUG(ah, HAL_DEBUG_BEACON, "%s: setting beacon timers\n", __func__);
123
124 HALASSERT(bs->bs_intval != 0);
125 /* if the AP will do PCF */
126 if (bs->bs_cfpmaxduration != 0) {
127 /* tell the h/w that the associated AP is PCF capable */
131
132 /* set CFP_PERIOD(1.024ms) register */
134
135 /* set CFP_DUR(1.024ms) register to max cfp duration */
137
138 /* set TIMER2(128us) to anticipated time of next CFP */
139 OS_REG_WRITE(ah, AR_TIMER2, bs->bs_cfpnext << 3);
140 } else {
141 /* tell the h/w that the associated AP is not PCF capable */
144 }
145
146 /*
147 * Set TIMER0(1.024ms) to the anticipated time of the next beacon.
148 */
150
151 /*
152 * Start the beacon timers by setting the BEACON register
153 * to the beacon interval; also write the tim offset which
154 * we should know by now. The code, in ar5211WriteAssocid,
155 * also sets the tim offset once the AID is known which can
156 * be left as such for now.
157 */
161 | SM(bs->bs_timoffset ? bs->bs_timoffset + 4 : 0, AR_BEACON_TIM)
162 );
163
164 /*
165 * Configure the BMISS interrupt. Note that we
166 * assume the caller blocks interrupts while enabling
167 * the threshold.
168 */
169
170 /*
171 * Interrupt works only on Crete.
172 */
173 if (AH_PRIVATE(ah)->ah_macRev < AR_SREV_CRETE)
174 return;
175 /*
176 * Counter is only 3-bits.
177 * Count of 0 with BMISS interrupt enabled will hang the system
178 * with too many interrupts
179 */
180 if (AH_PRIVATE(ah)->ah_macRev >= AR_SREV_CRETE &&
181 (bs->bs_bmissthreshold&7) == 0) {
182#ifdef AH_DEBUG
183 ath_hal_printf(ah, "%s: invalid beacon miss threshold %u\n",
184 __func__, bs->bs_bmissthreshold);
185#endif
186 return;
187 }
188#define BMISS_MAX (AR_RSSI_THR_BM_THR >> AR_RSSI_THR_BM_THR_S)
189 /*
190 * Configure the BMISS interrupt. Note that we
191 * assume the caller blocks interrupts while enabling
192 * the threshold.
193 *
194 * NB: the beacon miss count field is only 3 bits which
195 * is much smaller than what's found on later parts;
196 * clamp overflow values as a safeguard.
197 */
198 ahp->ah_rssiThr = (ahp->ah_rssiThr &~ AR_RSSI_THR_BM_THR)
203#undef BMISS_MAX
204}
@ HAL_M_STA
Definition: ah.h:765
@ HAL_DEBUG_BEACON
Definition: ah_debug.h:45
#define SM(_v, _f)
Definition: ah_internal.h:587
#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
void ath_hal_printf(struct ath_hal *, const char *,...)
Definition: ah_osdep.c:80
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
#define AH5210(ah)
Definition: ar5210.h:128
void ar5210ResetStaBeaconTimers(struct ath_hal *ah)
Definition: ar5210_beacon.c:96
#define TU_TO_TSF(_tu)
void ar5210BeaconInit(struct ath_hal *ah, uint32_t next_beacon, uint32_t beacon_period)
Definition: ar5210_beacon.c:63
#define BMISS_MAX
uint64_t ar5210GetNextTBTT(struct ath_hal *ah)
Definition: ar5210_beacon.c:35
void ar5210SetStaBeaconTimers(struct ath_hal *ah, const HAL_BEACON_STATE *bs)
void ar5210SetBeaconTimers(struct ath_hal *ah, const HAL_BEACON_TIMERS *bt)
Definition: ar5210_beacon.c:46
#define AR_BEACON_PERIOD
Definition: ar5210reg.h:348
#define AR_STA_ID1_NO_PSPOLL
Definition: ar5210reg.h:308
#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_SREV_CRETE
Definition: ar5210reg.h:293
#define AR_STA_ID1_DEFAULT_ANTENNA
Definition: ar5210reg.h:311
uint16_t bs_cfpmaxduration
Definition: ah.h:844
uint16_t bs_timoffset
Definition: ah.h:846
uint16_t bs_cfpperiod
Definition: ah.h:843
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 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: ar5210.h:119
Definition: ah.h:1219
HAL_OPS_CONFIG ah_config
Definition: ah.h:1243