xref: /freebsd/sys/dev/ath/ath_hal/ar5211/ar5211.h (revision 4928135658a9d0eaee37003df6137ab363fcb0b4)
1 /*-
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5  * Copyright (c) 2002-2006 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 #ifndef _ATH_AR5211_H_
22 #define _ATH_AR5211_H_
23 
24 #include "ah_eeprom.h"
25 
26 #define	AR5211_MAGIC	0x19570405
27 
28 /* Classes for WME streams */
29 #define	AC_BK	0
30 #define	AC_BE	1
31 #define	AC_VI	2
32 #define	AC_VO	3
33 
34 /* DCU Transmit Filter macros */
35 #define CALC_MMR(dcu, idx) \
36 	( (4 * dcu) + (idx < 32 ? 0 : (idx < 64 ? 1 : (idx < 96 ? 2 : 3))) )
37 #define TXBLK_FROM_MMR(mmr) \
38 	(AR_D_TXBLK_BASE + ((mmr & 0x1f) << 6) + ((mmr & 0x20) >> 3))
39 #define CALC_TXBLK_ADDR(dcu, idx)	(TXBLK_FROM_MMR(CALC_MMR(dcu, idx)))
40 #define CALC_TXBLK_VALUE(idx)		(1 << (idx & 0x1f))
41 
42 /* MAC register values */
43 
44 #define INIT_INTERRUPT_MASK \
45 	( AR_IMR_TXERR  | AR_IMR_TXOK | AR_IMR_RXORN | \
46 	  AR_IMR_RXERR  | AR_IMR_RXOK | AR_IMR_TXURN | \
47 	  AR_IMR_HIUERR )
48 #define INIT_BEACON_CONTROL \
49 	( (INIT_RESET_TSF << 24)  | (INIT_BEACON_EN << 23) | \
50 	  (INIT_TIM_OFFSET << 16) | INIT_BEACON_PERIOD )
51 
52 #define INIT_CONFIG_STATUS	0x00000000
53 #define INIT_RSSI_THR		0x00000700	/* Missed beacon counter initialized to 0x7 (max is 0xff) */
54 #define INIT_IQCAL_LOG_COUNT_MAX	0xF
55 #define INIT_BCON_CNTRL_REG	0x00000000
56 
57 #define INIT_BEACON_PERIOD	0xffff
58 #define INIT_TIM_OFFSET		0
59 #define INIT_BEACON_EN		0		/* this should be set by AP only when it's ready */
60 #define INIT_RESET_TSF		0
61 
62 /*
63  * Various fifo fill before Tx start, in 64-byte units
64  * i.e. put the frame in the air while still DMAing
65  */
66 #define MIN_TX_FIFO_THRESHOLD	   0x1
67 #define MAX_TX_FIFO_THRESHOLD	   ((IEEE80211_MAX_LEN / 64) + 1)
68 #define INIT_TX_FIFO_THRESHOLD	  MIN_TX_FIFO_THRESHOLD
69 
70 /*
71  * Gain support.
72  */
73 typedef struct _gainOptStep {
74 	int16_t	paramVal[4];
75 	int32_t	stepGain;
76 	int8_t	stepName[16];
77 } GAIN_OPTIMIZATION_STEP;
78 
79 typedef struct {
80 	uint32_t	numStepsInLadder;
81 	uint32_t	defaultStepNum;
82 	GAIN_OPTIMIZATION_STEP optStep[10];
83 } GAIN_OPTIMIZATION_LADDER;
84 
85 typedef struct {
86 	uint32_t	currStepNum;
87 	uint32_t	currGain;
88 	uint32_t	targetGain;
89 	uint32_t	loTrig;
90 	uint32_t	hiTrig;
91 	uint32_t	active;
92 	const GAIN_OPTIMIZATION_STEP *currStep;
93 } GAIN_VALUES;
94 
95 enum {
96 	RFGAIN_INACTIVE,
97 	RFGAIN_READ_REQUESTED,
98 	RFGAIN_NEED_CHANGE
99 };
100 
101 /*
102  * Header Info - general parameters and
103  * values set for each chipset board solution
104  * that are programmed every reset
105  */
106 struct ath_hal_5211 {
107 	struct ath_hal_private	ah_priv;	/* base class */
108 
109 	GAIN_VALUES	ah_gainValues;
110 
111 	uint8_t		ah_macaddr[IEEE80211_ADDR_LEN];
112 	uint8_t		ah_bssid[IEEE80211_ADDR_LEN];
113 
114 	/*
115 	 * Runtime state.
116 	 */
117 	uint32_t	ah_maskReg;		/* copy of AR_IMR */
118 	uint32_t	ah_txOkInterruptMask;
119 	uint32_t	ah_txErrInterruptMask;
120 	uint32_t	ah_txDescInterruptMask;
121 	uint32_t	ah_txEolInterruptMask;
122 	uint32_t	ah_txUrnInterruptMask;
123 	HAL_TX_QUEUE_INFO ah_txq[HAL_NUM_TX_QUEUES];
124 	HAL_ANT_SETTING ah_diversityControl;	/* antenna setting */
125 	uint32_t	ah_calibrationTime;
126 	HAL_BOOL	ah_bIQCalibration;
127 	int		ah_rfgainState;
128 	uint32_t	ah_tx6PowerInHalfDbm;	/* power output for 6Mb tx */
129 	uint32_t	ah_staId1Defaults;	/* STA_ID1 default settings */
130 	uint32_t	ah_beaconInterval;
131 	uint32_t	ah_rssiThr;		/* RSSI_THR settings */
132 
133 	u_int		ah_sifstime;		/* user-specified sifs time */
134 	u_int		ah_slottime;		/* user-specified slot time */
135 	u_int		ah_acktimeout;		/* user-specified ack timeout */
136 	u_int		ah_ctstimeout;		/* user-specified cts timeout */
137 	/*
138 	 * RF Silent handling.
139 	 */
140 	uint32_t	ah_gpioSelect;		/* GPIO pin to use */
141 	uint32_t	ah_polarity;		/* polarity to disable RF */
142 	uint32_t	ah_gpioBit;		/* after init, prev value */
143 };
144 #define	AH5211(ah)	((struct ath_hal_5211 *)(ah))
145 
146 struct ath_hal;
147 
148 extern	void ar5211Detach(struct ath_hal *);
149 
150 extern	HAL_BOOL ar5211Reset(struct ath_hal *, HAL_OPMODE,
151 		struct ieee80211_channel *, HAL_BOOL bChannelChange,
152 		HAL_RESET_TYPE,
153 		HAL_STATUS *);
154 extern	HAL_BOOL ar5211PhyDisable(struct ath_hal *);
155 extern	HAL_BOOL ar5211Disable(struct ath_hal *);
156 extern	HAL_BOOL ar5211ChipReset(struct ath_hal *,
157 		const struct ieee80211_channel *);
158 extern	HAL_BOOL ar5211PerCalibration(struct ath_hal *, struct ieee80211_channel *, HAL_BOOL *);
159 extern	HAL_BOOL ar5211PerCalibrationN(struct ath_hal *ah, struct ieee80211_channel *chan,
160 		u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone);
161 extern	HAL_BOOL ar5211ResetCalValid(struct ath_hal *ah, const struct ieee80211_channel *);
162 extern	HAL_BOOL ar5211SetTxPowerLimit(struct ath_hal *, uint32_t limit);
163 extern	HAL_BOOL ar5211CalNoiseFloor(struct ath_hal *,
164 		const struct ieee80211_channel *);
165 extern	HAL_BOOL ar5211SetAntennaSwitchInternal(struct ath_hal *,
166 		HAL_ANT_SETTING, const struct ieee80211_channel *);
167 extern	int16_t ar5211GetNfAdjust(struct ath_hal *,
168 		const HAL_CHANNEL_INTERNAL *);
169 extern	HAL_BOOL ar5211ResetDma(struct ath_hal *, HAL_OPMODE);
170 extern	void ar5211InitializeGainValues(struct ath_hal *);
171 extern	HAL_RFGAIN ar5211GetRfgain(struct ath_hal *);
172 extern	void ar5211SetPCUConfig(struct ath_hal *);
173 
174 extern  HAL_BOOL ar5211SetTxQueueProps(struct ath_hal *ah, int q,
175 		const HAL_TXQ_INFO *qInfo);
176 extern	HAL_BOOL ar5211GetTxQueueProps(struct ath_hal *ah, int q,
177 		HAL_TXQ_INFO *qInfo);
178 extern	int ar5211SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
179 		const HAL_TXQ_INFO *qInfo);
180 extern	HAL_BOOL ar5211ReleaseTxQueue(struct ath_hal *ah, u_int q);
181 extern	HAL_BOOL ar5211ResetTxQueue(struct ath_hal *ah, u_int q);
182 extern	uint32_t ar5211GetTxDP(struct ath_hal *, u_int);
183 extern	HAL_BOOL ar5211SetTxDP(struct ath_hal *, u_int, uint32_t txdp);
184 extern	HAL_BOOL ar5211UpdateTxTrigLevel(struct ath_hal *, HAL_BOOL);
185 extern	HAL_BOOL ar5211StartTxDma(struct ath_hal *, u_int);
186 extern	HAL_BOOL ar5211StopTxDma(struct ath_hal *, u_int);
187 extern	uint32_t ar5211NumTxPending(struct ath_hal *, u_int qnum);
188 extern	HAL_BOOL ar5211IsTxQueueStopped(struct ath_hal *, u_int);
189 extern	HAL_BOOL ar5211GetTransmitFilterIndex(struct ath_hal *, uint32_t);
190 extern	HAL_BOOL ar5211SetupTxDesc(struct ath_hal *, struct ath_desc *,
191 		u_int pktLen, u_int hdrLen, HAL_PKT_TYPE type, u_int txPower,
192 		u_int txRate0, u_int txTries0,
193 		u_int keyIx, u_int antMode, u_int flags,
194 		u_int rtsctsRate, u_int rtsctsDuration,
195                 u_int compicvLen, u_int compivLen, u_int comp);
196 extern	HAL_BOOL ar5211SetupXTxDesc(struct ath_hal *, struct ath_desc *,
197 		u_int txRate1, u_int txRetries1,
198 		u_int txRate2, u_int txRetries2,
199 		u_int txRate3, u_int txRetries3);
200 extern	HAL_BOOL ar5211FillTxDesc(struct ath_hal *, struct ath_desc *,
201 		HAL_DMA_ADDR *bufAddrList, uint32_t *segLenList,
202 		u_int descId, u_int qcuId, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
203 		const struct ath_desc *ds0);
204 extern	HAL_STATUS ar5211ProcTxDesc(struct ath_hal *,
205 		struct ath_desc *, struct ath_tx_status *);
206 extern  void ar5211GetTxIntrQueue(struct ath_hal *ah, uint32_t *);
207 extern  void ar5211IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *);
208 extern	HAL_BOOL ar5211GetTxCompletionRates(struct ath_hal *ah,
209 		const struct ath_desc *ds0, int *rates, int *tries);
210 extern	void ar5211SetTxDescLink(struct ath_hal *ah, void *ds,
211 		uint32_t link);
212 extern	void ar5211GetTxDescLink(struct ath_hal *ah, void *ds,
213 		uint32_t *link);
214 extern	void ar5211GetTxDescLinkPtr(struct ath_hal *ah, void *ds,
215 		uint32_t **linkptr);
216 
217 extern	uint32_t ar5211GetRxDP(struct ath_hal *, HAL_RX_QUEUE);
218 extern	void ar5211SetRxDP(struct ath_hal *, uint32_t rxdp, HAL_RX_QUEUE);
219 extern	void ar5211EnableReceive(struct ath_hal *);
220 extern	HAL_BOOL ar5211StopDmaReceive(struct ath_hal *);
221 extern	void ar5211StartPcuReceive(struct ath_hal *);
222 extern	void ar5211StopPcuReceive(struct ath_hal *);
223 extern	void ar5211SetMulticastFilter(struct ath_hal *,
224 		uint32_t filter0, uint32_t filter1);
225 extern	HAL_BOOL ar5211ClrMulticastFilterIndex(struct ath_hal *, uint32_t);
226 extern	HAL_BOOL ar5211SetMulticastFilterIndex(struct ath_hal *, uint32_t);
227 extern	uint32_t ar5211GetRxFilter(struct ath_hal *);
228 extern	void ar5211SetRxFilter(struct ath_hal *, uint32_t);
229 extern	HAL_BOOL ar5211SetupRxDesc(struct ath_hal *, struct ath_desc *,
230 		uint32_t, u_int flags);
231 extern	HAL_STATUS ar5211ProcRxDesc(struct ath_hal *, struct ath_desc *,
232 		uint32_t, struct ath_desc *, uint64_t,
233 		struct ath_rx_status *);
234 
235 extern	void ar5211GetMacAddress(struct ath_hal *, uint8_t *);
236 extern	HAL_BOOL ar5211SetMacAddress(struct ath_hal *ah, const uint8_t *);
237 extern	void ar5211GetBssIdMask(struct ath_hal *, uint8_t *);
238 extern	HAL_BOOL ar5211SetBssIdMask(struct ath_hal *, const uint8_t *);
239 extern	HAL_BOOL ar5211EepromRead(struct ath_hal *, u_int off, uint16_t *data);
240 extern	HAL_BOOL ar5211EepromWrite(struct ath_hal *, u_int off, uint16_t data);
241 extern	HAL_BOOL ar5211SetRegulatoryDomain(struct ath_hal *,
242 		uint16_t, HAL_STATUS *);
243 extern	u_int ar5211GetWirelessModes(struct ath_hal *);
244 extern	void ar5211EnableRfKill(struct ath_hal *);
245 extern	uint32_t ar5211GpioGet(struct ath_hal *, uint32_t gpio);
246 extern	void ar5211GpioSetIntr(struct ath_hal *, u_int, uint32_t ilevel);
247 extern	HAL_BOOL ar5211GpioCfgOutput(struct ath_hal *, uint32_t gpio,
248 		HAL_GPIO_MUX_TYPE);
249 extern	HAL_BOOL ar5211GpioCfgInput(struct ath_hal *, uint32_t gpio);
250 extern	HAL_BOOL ar5211GpioSet(struct ath_hal *, uint32_t gpio, uint32_t val);
251 extern	void ar5211SetLedState(struct ath_hal *, HAL_LED_STATE);
252 extern	u_int ar5211AntennaGet(struct ath_hal *);
253 extern	void ar5211WriteAssocid(struct ath_hal *,
254 		const uint8_t *bssid, uint16_t assocId);
255 extern	uint64_t ar5211GetTsf64(struct ath_hal *);
256 extern	uint32_t ar5211GetTsf32(struct ath_hal *);
257 extern	void ar5211ResetTsf(struct ath_hal *);
258 extern	uint32_t ar5211GetMaxTurboRate(struct ath_hal *);
259 extern	uint32_t ar5211GetRandomSeed(struct ath_hal *);
260 extern	HAL_BOOL ar5211DetectCardPresent(struct ath_hal *);
261 extern	void ar5211UpdateMibCounters(struct ath_hal *, HAL_MIB_STATS *);
262 extern	void ar5211EnableHwEncryption(struct ath_hal *);
263 extern	void ar5211DisableHwEncryption(struct ath_hal *);
264 extern	HAL_BOOL ar5211SetSlotTime(struct ath_hal *, u_int);
265 extern	u_int ar5211GetSlotTime(struct ath_hal *);
266 extern	HAL_BOOL ar5211SetAckTimeout(struct ath_hal *, u_int);
267 extern	u_int ar5211GetAckTimeout(struct ath_hal *);
268 extern	HAL_BOOL ar5211SetAckCTSRate(struct ath_hal *, u_int);
269 extern	u_int ar5211GetAckCTSRate(struct ath_hal *);
270 extern	HAL_BOOL ar5211SetCTSTimeout(struct ath_hal *, u_int);
271 extern	u_int ar5211GetCTSTimeout(struct ath_hal *);
272 extern	HAL_BOOL ar5211SetSifsTime(struct ath_hal *, u_int);
273 extern	u_int ar5211GetSifsTime(struct ath_hal *);
274 extern  HAL_BOOL ar5211SetDecompMask(struct ath_hal *, uint16_t, int);
275 extern	void ar5211SetCoverageClass(struct ath_hal *, uint8_t, int);
276 extern	HAL_STATUS ar5211SetQuiet(struct ath_hal *, uint32_t, uint32_t,
277 		uint32_t, HAL_QUIET_FLAG);
278 extern	uint32_t ar5211GetCurRssi(struct ath_hal *);
279 extern	u_int ar5211GetDefAntenna(struct ath_hal *);
280 extern	void ar5211SetDefAntenna(struct ath_hal *ah, u_int antenna);
281 extern	HAL_ANT_SETTING ar5211GetAntennaSwitch(struct ath_hal *);
282 extern	HAL_BOOL ar5211SetAntennaSwitch(struct ath_hal *, HAL_ANT_SETTING);
283 extern	HAL_STATUS ar5211GetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
284 		uint32_t, uint32_t *);
285 extern	HAL_BOOL ar5211SetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
286 		uint32_t, uint32_t, HAL_STATUS *);
287 extern	HAL_BOOL ar5211GetDiagState(struct ath_hal *ah, int request,
288 		const void *args, uint32_t argsize,
289 		void **result, uint32_t *resultsize);
290 extern	uint32_t ar5211Get11nExtBusy(struct ath_hal *);
291 extern	HAL_BOOL ar5211GetMibCycleCounts(struct ath_hal *,
292 		HAL_SURVEY_SAMPLE *);
293 extern	void ar5211SetChainMasks(struct ath_hal *ah, uint32_t, uint32_t);
294 
295 extern	void ar5211EnableDfs(struct ath_hal *, HAL_PHYERR_PARAM *);
296 extern	void ar5211GetDfsThresh(struct ath_hal *, HAL_PHYERR_PARAM *);
297 
298 extern	u_int ar5211GetKeyCacheSize(struct ath_hal *);
299 extern	HAL_BOOL ar5211IsKeyCacheEntryValid(struct ath_hal *, uint16_t);
300 extern	HAL_BOOL ar5211ResetKeyCacheEntry(struct ath_hal *, uint16_t entry);
301 extern	HAL_BOOL ar5211SetKeyCacheEntry(struct ath_hal *, uint16_t entry,
302                        const HAL_KEYVAL *, const uint8_t *mac,
303                        int xorKey);
304 extern	HAL_BOOL ar5211SetKeyCacheEntryMac(struct ath_hal *,
305 			uint16_t, const uint8_t *);
306 
307 extern	HAL_BOOL ar5211SetPowerMode(struct ath_hal *, uint32_t powerRequest,
308 		int setChip);
309 extern	HAL_POWER_MODE ar5211GetPowerMode(struct ath_hal *);
310 
311 extern	void ar5211SetBeaconTimers(struct ath_hal *,
312 		const HAL_BEACON_TIMERS *);
313 extern	void ar5211BeaconInit(struct ath_hal *, uint32_t, uint32_t);
314 extern	void ar5211SetStaBeaconTimers(struct ath_hal *,
315 		const HAL_BEACON_STATE *);
316 extern	void ar5211ResetStaBeaconTimers(struct ath_hal *);
317 extern	uint64_t ar5211GetNextTBTT(struct ath_hal *);
318 
319 extern	HAL_BOOL ar5211IsInterruptPending(struct ath_hal *);
320 extern	HAL_BOOL ar5211GetPendingInterrupts(struct ath_hal *, HAL_INT *);
321 extern	HAL_INT ar5211GetInterrupts(struct ath_hal *);
322 extern	HAL_INT ar5211SetInterrupts(struct ath_hal *, HAL_INT ints);
323 
324 extern	const HAL_RATE_TABLE *ar5211GetRateTable(struct ath_hal *, u_int mode);
325 
326 extern	HAL_BOOL ar5211AniControl(struct ath_hal *, HAL_ANI_CMD, int );
327 extern	void ar5211RxMonitor(struct ath_hal *, const HAL_NODE_STATS *,
328 		const struct ieee80211_channel *);
329 extern	void ar5211AniPoll(struct ath_hal *, const struct ieee80211_channel *);
330 extern	void ar5211MibEvent(struct ath_hal *, const HAL_NODE_STATS *);
331 #endif /* _ATH_AR5211_H_ */
332