ar5211.h revision 185380
1/*
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2006 Atheros Communications, Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 *
17 * $Id: ar5211.h,v 1.8 2008/11/10 22:08:47 sam Exp $
18 */
19#ifndef _ATH_AR5211_H_
20#define _ATH_AR5211_H_
21
22#include "ah_eeprom.h"
23
24#define	AR5211_MAGIC	0x19570405
25
26/* Classes for WME streams */
27#define	AC_BK	0
28#define	AC_BE	1
29#define	AC_VI	2
30#define	AC_VO	3
31
32/* DCU Transmit Filter macros */
33#define CALC_MMR(dcu, idx) \
34	( (4 * dcu) + (idx < 32 ? 0 : (idx < 64 ? 1 : (idx < 96 ? 2 : 3))) )
35#define TXBLK_FROM_MMR(mmr) \
36	(AR_D_TXBLK_BASE + ((mmr & 0x1f) << 6) + ((mmr & 0x20) >> 3))
37#define CALC_TXBLK_ADDR(dcu, idx)	(TXBLK_FROM_MMR(CALC_MMR(dcu, idx)))
38#define CALC_TXBLK_VALUE(idx)		(1 << (idx & 0x1f))
39
40/* MAC register values */
41
42#define INIT_INTERRUPT_MASK \
43	( AR_IMR_TXERR  | AR_IMR_TXOK | AR_IMR_RXORN | \
44	  AR_IMR_RXERR  | AR_IMR_RXOK | AR_IMR_TXURN | \
45	  AR_IMR_HIUERR )
46#define INIT_BEACON_CONTROL \
47	( (INIT_RESET_TSF << 24)  | (INIT_BEACON_EN << 23) | \
48	  (INIT_TIM_OFFSET << 16) | INIT_BEACON_PERIOD )
49
50#define INIT_CONFIG_STATUS	0x00000000
51#define INIT_RSSI_THR		0x00000700	/* Missed beacon counter initialized to 0x7 (max is 0xff) */
52#define INIT_IQCAL_LOG_COUNT_MAX	0xF
53#define INIT_BCON_CNTRL_REG	0x00000000
54
55#define INIT_BEACON_PERIOD	0xffff
56#define INIT_TIM_OFFSET		0
57#define INIT_BEACON_EN		0		/* this should be set by AP only when it's ready */
58#define INIT_RESET_TSF		0
59
60/*
61 * Various fifo fill before Tx start, in 64-byte units
62 * i.e. put the frame in the air while still DMAing
63 */
64#define MIN_TX_FIFO_THRESHOLD	   0x1
65#define MAX_TX_FIFO_THRESHOLD	   ((IEEE80211_MAX_LEN / 64) + 1)
66#define INIT_TX_FIFO_THRESHOLD	  MIN_TX_FIFO_THRESHOLD
67
68/*
69 * Gain support.
70 */
71typedef struct _gainOptStep {
72	int16_t	paramVal[4];
73	int32_t	stepGain;
74	int8_t	stepName[16];
75} GAIN_OPTIMIZATION_STEP;
76
77typedef struct {
78	uint32_t	numStepsInLadder;
79	uint32_t	defaultStepNum;
80	GAIN_OPTIMIZATION_STEP optStep[10];
81} GAIN_OPTIMIZATION_LADDER;
82
83typedef struct {
84	uint32_t	currStepNum;
85	uint32_t	currGain;
86	uint32_t	targetGain;
87	uint32_t	loTrig;
88	uint32_t	hiTrig;
89	uint32_t	active;
90	const GAIN_OPTIMIZATION_STEP *currStep;
91} GAIN_VALUES;
92
93enum {
94	RFGAIN_INACTIVE,
95	RFGAIN_READ_REQUESTED,
96	RFGAIN_NEED_CHANGE
97};
98
99/*
100 * Header Info - general parameters and
101 * values set for each chipset board solution
102 * that are programmed every reset
103 */
104struct ath_hal_5211 {
105	struct ath_hal_private	ah_priv;	/* base class */
106
107	GAIN_VALUES	ah_gainValues;
108
109	uint8_t		ah_macaddr[IEEE80211_ADDR_LEN];
110	uint8_t		ah_bssid[IEEE80211_ADDR_LEN];
111
112	/*
113	 * Runtime state.
114	 */
115	uint32_t	ah_maskReg;		/* copy of AR_IMR */
116	uint32_t	ah_txOkInterruptMask;
117	uint32_t	ah_txErrInterruptMask;
118	uint32_t	ah_txDescInterruptMask;
119	uint32_t	ah_txEolInterruptMask;
120	uint32_t	ah_txUrnInterruptMask;
121	HAL_TX_QUEUE_INFO ah_txq[HAL_NUM_TX_QUEUES];
122	HAL_POWER_MODE	ah_powerMode;
123	HAL_ANT_SETTING ah_diversityControl;	/* antenna setting */
124	uint32_t	ah_calibrationTime;
125	HAL_BOOL	ah_bIQCalibration;
126	HAL_CHANNEL	ah_curchan;		/* XXX */
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
146struct ath_hal;
147
148extern	struct ath_hal *ar5211Attach(uint16_t, HAL_SOFTC,
149	HAL_BUS_TAG, HAL_BUS_HANDLE, HAL_STATUS *);
150extern	void ar5211Detach(struct ath_hal *);
151
152extern	HAL_BOOL ar5211Reset(struct ath_hal *, HAL_OPMODE,
153		HAL_CHANNEL *, HAL_BOOL bChannelChange, HAL_STATUS *);
154extern	HAL_BOOL ar5211PhyDisable(struct ath_hal *);
155extern	HAL_BOOL ar5211Disable(struct ath_hal *);
156extern	HAL_BOOL ar5211ChipReset(struct ath_hal *, uint16_t);
157extern	HAL_BOOL ar5211PerCalibration(struct ath_hal *, HAL_CHANNEL *, HAL_BOOL *);
158extern	HAL_BOOL ar5211PerCalibrationN(struct ath_hal *ah, HAL_CHANNEL *chan,
159		u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone);
160extern	HAL_BOOL ar5211ResetCalValid(struct ath_hal *ah, HAL_CHANNEL *chan);
161extern	HAL_BOOL ar5211SetTxPowerLimit(struct ath_hal *, uint32_t limit);
162extern	HAL_BOOL ar5211SetTransmitPower(struct ath_hal *, HAL_CHANNEL *);
163extern	HAL_BOOL ar5211CalNoiseFloor(struct ath_hal *, HAL_CHANNEL_INTERNAL *);
164extern	HAL_BOOL ar5211SetAntennaSwitchInternal(struct ath_hal *,
165		HAL_ANT_SETTING, const HAL_CHANNEL *);
166extern	int16_t ar5211GetNfAdjust(struct ath_hal *,
167		const HAL_CHANNEL_INTERNAL *);
168extern	HAL_BOOL ar5211ResetDma(struct ath_hal *, HAL_OPMODE);
169extern	void ar5211InitializeGainValues(struct ath_hal *);
170extern	HAL_RFGAIN ar5211GetRfgain(struct ath_hal *);
171extern	void ar5211SetPCUConfig(struct ath_hal *);
172
173extern  HAL_BOOL ar5211SetTxQueueProps(struct ath_hal *ah, int q,
174		const HAL_TXQ_INFO *qInfo);
175extern	HAL_BOOL ar5211GetTxQueueProps(struct ath_hal *ah, int q,
176		HAL_TXQ_INFO *qInfo);
177extern	int ar5211SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
178		const HAL_TXQ_INFO *qInfo);
179extern	HAL_BOOL ar5211ReleaseTxQueue(struct ath_hal *ah, u_int q);
180extern	HAL_BOOL ar5211ResetTxQueue(struct ath_hal *ah, u_int q);
181extern	uint32_t ar5211GetTxDP(struct ath_hal *, u_int);
182extern	HAL_BOOL ar5211SetTxDP(struct ath_hal *, u_int, uint32_t txdp);
183extern	HAL_BOOL ar5211UpdateTxTrigLevel(struct ath_hal *, HAL_BOOL);
184extern	HAL_BOOL ar5211StartTxDma(struct ath_hal *, u_int);
185extern	HAL_BOOL ar5211StopTxDma(struct ath_hal *, u_int);
186extern	uint32_t ar5211NumTxPending(struct ath_hal *, u_int qnum);
187extern	HAL_BOOL ar5211IsTxQueueStopped(struct ath_hal *, u_int);
188extern	HAL_BOOL ar5211GetTransmitFilterIndex(struct ath_hal *, uint32_t);
189extern	HAL_BOOL ar5211SetupTxDesc(struct ath_hal *, struct ath_desc *,
190		u_int pktLen, u_int hdrLen, HAL_PKT_TYPE type, u_int txPower,
191		u_int txRate0, u_int txTries0,
192		u_int keyIx, u_int antMode, u_int flags,
193		u_int rtsctsRate, u_int rtsctsDuration,
194                u_int compicvLen, u_int compivLen, u_int comp);
195extern	HAL_BOOL ar5211SetupXTxDesc(struct ath_hal *, struct ath_desc *,
196		u_int txRate1, u_int txRetries1,
197		u_int txRate2, u_int txRetries2,
198		u_int txRate3, u_int txRetries3);
199extern	HAL_BOOL ar5211FillTxDesc(struct ath_hal *, struct ath_desc *,
200		u_int segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
201		const struct ath_desc *ds0);
202extern	HAL_STATUS ar5211ProcTxDesc(struct ath_hal *,
203		struct ath_desc *, struct ath_tx_status *);
204extern  void ar5211GetTxIntrQueue(struct ath_hal *ah, uint32_t *);
205extern  void ar5211IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *);
206
207extern	uint32_t ar5211GetRxDP(struct ath_hal *);
208extern	void ar5211SetRxDP(struct ath_hal *, uint32_t rxdp);
209extern	void ar5211EnableReceive(struct ath_hal *);
210extern	HAL_BOOL ar5211StopDmaReceive(struct ath_hal *);
211extern	void ar5211StartPcuReceive(struct ath_hal *);
212extern	void ar5211StopPcuReceive(struct ath_hal *);
213extern	void ar5211SetMulticastFilter(struct ath_hal *,
214		uint32_t filter0, uint32_t filter1);
215extern	HAL_BOOL ar5211ClrMulticastFilterIndex(struct ath_hal *, uint32_t);
216extern	HAL_BOOL ar5211SetMulticastFilterIndex(struct ath_hal *, uint32_t);
217extern	uint32_t ar5211GetRxFilter(struct ath_hal *);
218extern	void ar5211SetRxFilter(struct ath_hal *, uint32_t);
219extern	HAL_BOOL ar5211SetupRxDesc(struct ath_hal *, struct ath_desc *,
220		uint32_t, u_int flags);
221extern	HAL_STATUS ar5211ProcRxDesc(struct ath_hal *, struct ath_desc *,
222		uint32_t, struct ath_desc *, uint64_t,
223		struct ath_rx_status *);
224
225extern	void ar5211GetMacAddress(struct ath_hal *, uint8_t *);
226extern	HAL_BOOL ar5211SetMacAddress(struct ath_hal *ah, const uint8_t *);
227extern	void ar5211GetBssIdMask(struct ath_hal *, uint8_t *);
228extern	HAL_BOOL ar5211SetBssIdMask(struct ath_hal *, const uint8_t *);
229extern	HAL_BOOL ar5211EepromRead(struct ath_hal *, u_int off, uint16_t *data);
230extern	HAL_BOOL ar5211EepromWrite(struct ath_hal *, u_int off, uint16_t data);
231extern	HAL_BOOL ar5211SetRegulatoryDomain(struct ath_hal *,
232		uint16_t, HAL_STATUS *);
233extern	u_int ar5211GetWirelessModes(struct ath_hal *);
234extern	void ar5211EnableRfKill(struct ath_hal *);
235extern	uint32_t ar5211GpioGet(struct ath_hal *, uint32_t gpio);
236extern	void ar5211GpioSetIntr(struct ath_hal *, u_int, uint32_t ilevel);
237extern	HAL_BOOL ar5211GpioCfgOutput(struct ath_hal *, uint32_t gpio);
238extern	HAL_BOOL ar5211GpioCfgInput(struct ath_hal *, uint32_t gpio);
239extern	HAL_BOOL ar5211GpioSet(struct ath_hal *, uint32_t gpio, uint32_t val);
240extern	void ar5211SetLedState(struct ath_hal *, HAL_LED_STATE);
241extern	u_int ar5211AntennaGet(struct ath_hal *);
242extern	void ar5211WriteAssocid(struct ath_hal *,
243		const uint8_t *bssid, uint16_t assocId);
244extern	uint64_t ar5211GetTsf64(struct ath_hal *);
245extern	uint32_t ar5211GetTsf32(struct ath_hal *);
246extern	void ar5211ResetTsf(struct ath_hal *);
247extern	uint32_t ar5211GetMaxTurboRate(struct ath_hal *);
248extern	uint32_t ar5211GetRandomSeed(struct ath_hal *);
249extern	HAL_BOOL ar5211DetectCardPresent(struct ath_hal *);
250extern	void ar5211UpdateMibCounters(struct ath_hal *, HAL_MIB_STATS *);
251extern	void ar5211EnableHwEncryption(struct ath_hal *);
252extern	void ar5211DisableHwEncryption(struct ath_hal *);
253extern	HAL_BOOL ar5211SetSlotTime(struct ath_hal *, u_int);
254extern	u_int ar5211GetSlotTime(struct ath_hal *);
255extern	HAL_BOOL ar5211SetAckTimeout(struct ath_hal *, u_int);
256extern	u_int ar5211GetAckTimeout(struct ath_hal *);
257extern	HAL_BOOL ar5211SetAckCTSRate(struct ath_hal *, u_int);
258extern	u_int ar5211GetAckCTSRate(struct ath_hal *);
259extern	HAL_BOOL ar5211SetCTSTimeout(struct ath_hal *, u_int);
260extern	u_int ar5211GetCTSTimeout(struct ath_hal *);
261extern	HAL_BOOL ar5211SetSifsTime(struct ath_hal *, u_int);
262extern	u_int ar5211GetSifsTime(struct ath_hal *);
263extern  HAL_BOOL ar5211SetDecompMask(struct ath_hal *, uint16_t, int);
264extern	void ar5211SetCoverageClass(struct ath_hal *, uint8_t, int);
265extern	uint32_t ar5211GetCurRssi(struct ath_hal *);
266extern	u_int ar5211GetDefAntenna(struct ath_hal *);
267extern	void ar5211SetDefAntenna(struct ath_hal *ah, u_int antenna);
268extern	HAL_ANT_SETTING ar5211GetAntennaSwitch(struct ath_hal *);
269extern	HAL_BOOL ar5211SetAntennaSwitch(struct ath_hal *, HAL_ANT_SETTING);
270extern	HAL_STATUS ar5211GetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
271		uint32_t, uint32_t *);
272extern	HAL_BOOL ar5211SetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
273		uint32_t, uint32_t, HAL_STATUS *);
274extern	HAL_BOOL ar5211GetDiagState(struct ath_hal *ah, int request,
275		const void *args, uint32_t argsize,
276		void **result, uint32_t *resultsize);
277
278extern	u_int ar5211GetKeyCacheSize(struct ath_hal *);
279extern	HAL_BOOL ar5211IsKeyCacheEntryValid(struct ath_hal *, uint16_t);
280extern	HAL_BOOL ar5211ResetKeyCacheEntry(struct ath_hal *, uint16_t entry);
281extern	HAL_BOOL ar5211SetKeyCacheEntry(struct ath_hal *, uint16_t entry,
282                       const HAL_KEYVAL *, const uint8_t *mac,
283                       int xorKey);
284extern	HAL_BOOL ar5211SetKeyCacheEntryMac(struct ath_hal *,
285			uint16_t, const uint8_t *);
286
287extern	HAL_BOOL ar5211SetPowerMode(struct ath_hal *, uint32_t powerRequest,
288		int setChip);
289extern	HAL_POWER_MODE ar5211GetPowerMode(struct ath_hal *);
290
291extern	void ar5211SetBeaconTimers(struct ath_hal *,
292		const HAL_BEACON_TIMERS *);
293extern	void ar5211BeaconInit(struct ath_hal *, uint32_t, uint32_t);
294extern	void ar5211SetStaBeaconTimers(struct ath_hal *,
295		const HAL_BEACON_STATE *);
296extern	void ar5211ResetStaBeaconTimers(struct ath_hal *);
297
298extern	HAL_BOOL ar5211IsInterruptPending(struct ath_hal *);
299extern	HAL_BOOL ar5211GetPendingInterrupts(struct ath_hal *, HAL_INT *);
300extern	HAL_INT ar5211GetInterrupts(struct ath_hal *);
301extern	HAL_INT ar5211SetInterrupts(struct ath_hal *, HAL_INT ints);
302
303extern	const HAL_RATE_TABLE *ar5211GetRateTable(struct ath_hal *, u_int mode);
304
305extern	HAL_BOOL ar5211AniControl(struct ath_hal *, HAL_ANI_CMD, int );
306extern	void ar5211AniPoll(struct ath_hal *, const HAL_NODE_STATS *, HAL_CHANNEL *);
307extern	void ar5211MibEvent(struct ath_hal *, const HAL_NODE_STATS *);
308#endif /* _ATH_AR5211_H_ */
309