ar5211.h revision 185377
154359Sroberto/*
254359Sroberto * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
354363Sroberto * Copyright (c) 2002-2006 Atheros Communications, Inc.
4132454Sroberto *
5132454Sroberto * Permission to use, copy, modify, and/or distribute this software for any
654359Sroberto * purpose with or without fee is hereby granted, provided that the above
754359Sroberto * copyright notice and this permission notice appear in all copies.
854359Sroberto *
954359Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1054359Sroberto * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1154359Sroberto * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1254359Sroberto * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1354359Sroberto * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1454359Sroberto * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1554359Sroberto * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1654359Sroberto *
1782505Sroberto * $Id: ar5211.h,v 1.7 2008/11/10 04:08:02 sam Exp $
1882505Sroberto */
1954359Sroberto#ifndef _ATH_AR5211_H_
2054359Sroberto#define _ATH_AR5211_H_
2154359Sroberto
2254359Sroberto#include "ah_eeprom.h"
2354359Sroberto
2454359Sroberto#define	AR5211_MAGIC	0x19570405
2554359Sroberto
2654359Sroberto/* Classes for WME streams */
2754359Sroberto#define	AC_BK	0
2882505Sroberto#define	AC_BE	1
2954359Sroberto#define	AC_VI	2
3054359Sroberto#define	AC_VO	3
3154359Sroberto
3254359Sroberto/* DCU Transmit Filter macros */
3354359Sroberto#define CALC_MMR(dcu, idx) \
3482505Sroberto	( (4 * dcu) + (idx < 32 ? 0 : (idx < 64 ? 1 : (idx < 96 ? 2 : 3))) )
3582505Sroberto#define TXBLK_FROM_MMR(mmr) \
3654359Sroberto	(AR_D_TXBLK_BASE + ((mmr & 0x1f) << 6) + ((mmr & 0x20) >> 3))
37132454Sroberto#define CALC_TXBLK_ADDR(dcu, idx)	(TXBLK_FROM_MMR(CALC_MMR(dcu, idx)))
3854359Sroberto#define CALC_TXBLK_VALUE(idx)		(1 << (idx & 0x1f))
3954359Sroberto
40132454Sroberto/* MAC register values */
4182505Sroberto
42132454Sroberto#define INIT_INTERRUPT_MASK \
43132454Sroberto	( AR_IMR_TXERR  | AR_IMR_TXOK | AR_IMR_RXORN | \
44132454Sroberto	  AR_IMR_RXERR  | AR_IMR_RXOK | AR_IMR_TXURN | \
4554359Sroberto	  AR_IMR_HIUERR )
46132454Sroberto#define INIT_BEACON_CONTROL \
4754359Sroberto	( (INIT_RESET_TSF << 24)  | (INIT_BEACON_EN << 23) | \
4854359Sroberto	  (INIT_TIM_OFFSET << 16) | INIT_BEACON_PERIOD )
4954359Sroberto
5054359Sroberto#define INIT_CONFIG_STATUS	0x00000000
51132454Sroberto#define INIT_RSSI_THR		0x00000700	/* Missed beacon counter initialized to 0x7 (max is 0xff) */
52132454Sroberto#define INIT_IQCAL_LOG_COUNT_MAX	0xF
53132454Sroberto#define INIT_BCON_CNTRL_REG	0x00000000
5454359Sroberto
5554359Sroberto#define INIT_BEACON_PERIOD	0xffff
56132454Sroberto#define INIT_TIM_OFFSET		0
5754359Sroberto#define INIT_BEACON_EN		0		/* this should be set by AP only when it's ready */
58132454Sroberto#define INIT_RESET_TSF		0
5982505Sroberto
6082505Sroberto/*
6182505Sroberto * Various fifo fill before Tx start, in 64-byte units
6282505Sroberto * i.e. put the frame in the air while still DMAing
63132454Sroberto */
64132454Sroberto#define MIN_TX_FIFO_THRESHOLD	   0x1
6582505Sroberto#define MAX_TX_FIFO_THRESHOLD	   ((IEEE80211_MAX_LEN / 64) + 1)
66132454Sroberto#define INIT_TX_FIFO_THRESHOLD	  MIN_TX_FIFO_THRESHOLD
6754359Sroberto
6854359Sroberto/*
69132454Sroberto * Gain support.
70132454Sroberto */
71132454Srobertotypedef struct _gainOptStep {
72132454Sroberto	int16_t	paramVal[4];
73132454Sroberto	int32_t	stepGain;
74132454Sroberto	int8_t	stepName[16];
75132454Sroberto} GAIN_OPTIMIZATION_STEP;
76132454Sroberto
77132454Srobertotypedef struct {
78132454Sroberto	uint32_t	numStepsInLadder;
79132454Sroberto	uint32_t	defaultStepNum;
8054359Sroberto	GAIN_OPTIMIZATION_STEP optStep[10];
8154359Sroberto} GAIN_OPTIMIZATION_LADDER;
82132454Sroberto
83132454Srobertotypedef struct {
8454359Sroberto	uint32_t	currStepNum;
85132454Sroberto	uint32_t	currGain;
86132454Sroberto	uint32_t	targetGain;
87132454Sroberto	uint32_t	loTrig;
88132454Sroberto	uint32_t	hiTrig;
89132454Sroberto	uint32_t	active;
90132454Sroberto	const GAIN_OPTIMIZATION_STEP *currStep;
91132454Sroberto} GAIN_VALUES;
9254359Sroberto
9354359Srobertoenum {
9454359Sroberto	RFGAIN_INACTIVE,
9554359Sroberto	RFGAIN_READ_REQUESTED,
9682505Sroberto	RFGAIN_NEED_CHANGE
9754359Sroberto};
9856749Sroberto
99132454Sroberto/*
10054359Sroberto * Header Info - general parameters and
10154359Sroberto * values set for each chipset board solution
10254359Sroberto * that are programmed every reset
10354359Sroberto */
10454359Srobertostruct ath_hal_5211 {
10554359Sroberto	struct ath_hal_private	ah_priv;	/* base class */
10654359Sroberto
10754359Sroberto	GAIN_VALUES	ah_gainValues;
10854359Sroberto
10954359Sroberto	uint8_t		ah_macaddr[IEEE80211_ADDR_LEN];
110132454Sroberto	uint8_t		ah_bssid[IEEE80211_ADDR_LEN];
11154359Sroberto
112132454Sroberto	/*
113132454Sroberto	 * Runtime state.
114132454Sroberto	 */
115132454Sroberto	uint32_t	ah_maskReg;		/* copy of AR_IMR */
116132454Sroberto	uint32_t	ah_txOkInterruptMask;
117132454Sroberto	uint32_t	ah_txErrInterruptMask;
118132454Sroberto	uint32_t	ah_txDescInterruptMask;
11954359Sroberto	uint32_t	ah_txEolInterruptMask;
120132454Sroberto	uint32_t	ah_txUrnInterruptMask;
12154359Sroberto	HAL_TX_QUEUE_INFO ah_txq[HAL_NUM_TX_QUEUES];
12254359Sroberto	HAL_POWER_MODE	ah_powerMode;
123132454Sroberto	HAL_ANT_SETTING ah_diversityControl;	/* antenna setting */
124132454Sroberto	uint32_t	ah_calibrationTime;
12554359Sroberto	HAL_BOOL	ah_bIQCalibration;
126132454Sroberto	HAL_CHANNEL	ah_curchan;		/* XXX */
127132454Sroberto	int		ah_rfgainState;
12882505Sroberto	uint32_t	ah_tx6PowerInHalfDbm;	/* power output for 6Mb tx */
129132454Sroberto	uint32_t	ah_staId1Defaults;	/* STA_ID1 default settings */
130132454Sroberto	uint32_t	ah_beaconInterval;
131132454Sroberto	uint32_t	ah_rssiThr;		/* RSSI_THR settings */
132132454Sroberto
133132454Sroberto	u_int		ah_sifstime;		/* user-specified sifs time */
134132454Sroberto	u_int		ah_slottime;		/* user-specified slot time */
135132454Sroberto	u_int		ah_acktimeout;		/* user-specified ack timeout */
136132454Sroberto	u_int		ah_ctstimeout;		/* user-specified cts timeout */
137132454Sroberto	/*
138132454Sroberto	 * RF Silent handling.
139132454Sroberto	 */
140132454Sroberto	uint32_t	ah_gpioSelect;		/* GPIO pin to use */
141132454Sroberto	uint32_t	ah_polarity;		/* polarity to disable RF */
142132454Sroberto	uint32_t	ah_gpioBit;		/* after init, prev value */
143132454Sroberto};
144132454Sroberto#define	AH5211(ah)	((struct ath_hal_5211 *)(ah))
145132454Sroberto
146132454Srobertostruct ath_hal;
147132454Sroberto
148132454Srobertoextern	struct ath_hal *ar5211Attach(uint16_t, HAL_SOFTC,
149132454Sroberto	HAL_BUS_TAG, HAL_BUS_HANDLE, HAL_STATUS *);
15082505Srobertoextern	void ar5211Detach(struct ath_hal *);
151132454Sroberto
152132454Srobertoextern	HAL_BOOL ar5211Reset(struct ath_hal *, HAL_OPMODE,
153132454Sroberto		HAL_CHANNEL *, HAL_BOOL bChannelChange, HAL_STATUS *);
154132454Srobertoextern	HAL_BOOL ar5211PhyDisable(struct ath_hal *);
155132454Srobertoextern	HAL_BOOL ar5211Disable(struct ath_hal *);
156132454Srobertoextern	HAL_BOOL ar5211ChipReset(struct ath_hal *, uint16_t);
157132454Srobertoextern	HAL_BOOL ar5211PerCalibration(struct ath_hal *, HAL_CHANNEL *, HAL_BOOL *);
158132454Srobertoextern	HAL_BOOL ar5211SetTxPowerLimit(struct ath_hal *, uint32_t limit);
159132454Srobertoextern	HAL_BOOL ar5211SetTransmitPower(struct ath_hal *, HAL_CHANNEL *);
160132454Srobertoextern	HAL_BOOL ar5211CalNoiseFloor(struct ath_hal *, HAL_CHANNEL_INTERNAL *);
161132454Srobertoextern	HAL_BOOL ar5211SetAntennaSwitchInternal(struct ath_hal *,
16282505Sroberto		HAL_ANT_SETTING, const HAL_CHANNEL *);
163132454Srobertoextern	int16_t ar5211GetNfAdjust(struct ath_hal *,
164132454Sroberto		const HAL_CHANNEL_INTERNAL *);
165132454Srobertoextern	HAL_BOOL ar5211ResetDma(struct ath_hal *, HAL_OPMODE);
166132454Srobertoextern	void ar5211InitializeGainValues(struct ath_hal *);
167132454Srobertoextern	HAL_RFGAIN ar5211GetRfgain(struct ath_hal *);
168132454Srobertoextern	void ar5211SetPCUConfig(struct ath_hal *);
169132454Sroberto
170132454Srobertoextern  HAL_BOOL ar5211SetTxQueueProps(struct ath_hal *ah, int q,
171132454Sroberto		const HAL_TXQ_INFO *qInfo);
172132454Srobertoextern	HAL_BOOL ar5211GetTxQueueProps(struct ath_hal *ah, int q,
173132454Sroberto		HAL_TXQ_INFO *qInfo);
17482505Srobertoextern	int ar5211SetupTxQueue(struct ath_hal *ah, HAL_TX_QUEUE type,
17582505Sroberto		const HAL_TXQ_INFO *qInfo);
17682505Srobertoextern	HAL_BOOL ar5211ReleaseTxQueue(struct ath_hal *ah, u_int q);
17782505Srobertoextern	HAL_BOOL ar5211ResetTxQueue(struct ath_hal *ah, u_int q);
178132454Srobertoextern	uint32_t ar5211GetTxDP(struct ath_hal *, u_int);
179132454Srobertoextern	HAL_BOOL ar5211SetTxDP(struct ath_hal *, u_int, uint32_t txdp);
18054359Srobertoextern	HAL_BOOL ar5211UpdateTxTrigLevel(struct ath_hal *, HAL_BOOL);
181132454Srobertoextern	HAL_BOOL ar5211StartTxDma(struct ath_hal *, u_int);
182132454Srobertoextern	HAL_BOOL ar5211StopTxDma(struct ath_hal *, u_int);
183132454Srobertoextern	uint32_t ar5211NumTxPending(struct ath_hal *, u_int qnum);
184132454Srobertoextern	HAL_BOOL ar5211IsTxQueueStopped(struct ath_hal *, u_int);
185132454Srobertoextern	HAL_BOOL ar5211GetTransmitFilterIndex(struct ath_hal *, uint32_t);
186132454Srobertoextern	HAL_BOOL ar5211SetupTxDesc(struct ath_hal *, struct ath_desc *,
187132454Sroberto		u_int pktLen, u_int hdrLen, HAL_PKT_TYPE type, u_int txPower,
188132454Sroberto		u_int txRate0, u_int txTries0,
189132454Sroberto		u_int keyIx, u_int antMode, u_int flags,
190132454Sroberto		u_int rtsctsRate, u_int rtsctsDuration,
191132454Sroberto                u_int compicvLen, u_int compivLen, u_int comp);
192132454Srobertoextern	HAL_BOOL ar5211SetupXTxDesc(struct ath_hal *, struct ath_desc *,
193132454Sroberto		u_int txRate1, u_int txRetries1,
194132454Sroberto		u_int txRate2, u_int txRetries2,
195132454Sroberto		u_int txRate3, u_int txRetries3);
196132454Srobertoextern	HAL_BOOL ar5211FillTxDesc(struct ath_hal *, struct ath_desc *,
197132454Sroberto		u_int segLen, HAL_BOOL firstSeg, HAL_BOOL lastSeg,
198132454Sroberto		const struct ath_desc *ds0);
199132454Srobertoextern	HAL_STATUS ar5211ProcTxDesc(struct ath_hal *,
200132454Sroberto		struct ath_desc *, struct ath_tx_status *);
201132454Srobertoextern  void ar5211GetTxIntrQueue(struct ath_hal *ah, uint32_t *);
202132454Srobertoextern  void ar5211IntrReqTxDesc(struct ath_hal *ah, struct ath_desc *);
203132454Sroberto
204132454Srobertoextern	uint32_t ar5211GetRxDP(struct ath_hal *);
205132454Srobertoextern	void ar5211SetRxDP(struct ath_hal *, uint32_t rxdp);
206132454Srobertoextern	void ar5211EnableReceive(struct ath_hal *);
207132454Srobertoextern	HAL_BOOL ar5211StopDmaReceive(struct ath_hal *);
208132454Srobertoextern	void ar5211StartPcuReceive(struct ath_hal *);
209132454Srobertoextern	void ar5211StopPcuReceive(struct ath_hal *);
210132454Srobertoextern	void ar5211SetMulticastFilter(struct ath_hal *,
211132454Sroberto		uint32_t filter0, uint32_t filter1);
212132454Srobertoextern	HAL_BOOL ar5211ClrMulticastFilterIndex(struct ath_hal *, uint32_t);
213132454Srobertoextern	HAL_BOOL ar5211SetMulticastFilterIndex(struct ath_hal *, uint32_t);
214132454Srobertoextern	uint32_t ar5211GetRxFilter(struct ath_hal *);
215132454Srobertoextern	void ar5211SetRxFilter(struct ath_hal *, uint32_t);
216132454Srobertoextern	HAL_BOOL ar5211SetupRxDesc(struct ath_hal *, struct ath_desc *,
217132454Sroberto		uint32_t, u_int flags);
218132454Srobertoextern	HAL_STATUS ar5211ProcRxDesc(struct ath_hal *, struct ath_desc *,
21982505Sroberto		uint32_t, struct ath_desc *, uint64_t,
22054359Sroberto		struct ath_rx_status *);
221132454Sroberto
222132454Srobertoextern	void ar5211GetMacAddress(struct ath_hal *, uint8_t *);
223132454Srobertoextern	HAL_BOOL ar5211SetMacAddress(struct ath_hal *ah, const uint8_t *);
224132454Srobertoextern	void ar5211GetBssIdMask(struct ath_hal *, uint8_t *);
225132454Srobertoextern	HAL_BOOL ar5211SetBssIdMask(struct ath_hal *, const uint8_t *);
226132454Srobertoextern	HAL_BOOL ar5211EepromRead(struct ath_hal *, u_int off, uint16_t *data);
22754359Srobertoextern	u_int ar5211GetWirelessModes(struct ath_hal *);
22854359Srobertoextern	void ar5211EnableRfKill(struct ath_hal *);
22954359Srobertoextern	uint32_t ar5211GpioGet(struct ath_hal *, uint32_t gpio);
23054359Srobertoextern	void ar5211GpioSetIntr(struct ath_hal *, u_int, uint32_t ilevel);
231132454Srobertoextern	HAL_BOOL ar5211GpioCfgOutput(struct ath_hal *, uint32_t gpio);
232132454Srobertoextern	HAL_BOOL ar5211GpioCfgInput(struct ath_hal *, uint32_t gpio);
23354359Srobertoextern	HAL_BOOL ar5211GpioSet(struct ath_hal *, uint32_t gpio, uint32_t val);
234132454Srobertoextern	void ar5211SetLedState(struct ath_hal *, HAL_LED_STATE);
235132454Srobertoextern	u_int ar5211AntennaGet(struct ath_hal *);
236132454Srobertoextern	void ar5211WriteAssocid(struct ath_hal *,
237132454Sroberto		const uint8_t *bssid, uint16_t assocId);
238132454Srobertoextern	uint64_t ar5211GetTsf64(struct ath_hal *);
239132454Srobertoextern	uint32_t ar5211GetTsf32(struct ath_hal *);
240132454Srobertoextern	void ar5211ResetTsf(struct ath_hal *);
241132454Srobertoextern	uint32_t ar5211GetMaxTurboRate(struct ath_hal *);
242132454Srobertoextern	uint32_t ar5211GetRandomSeed(struct ath_hal *);
243132454Srobertoextern	HAL_BOOL ar5211DetectCardPresent(struct ath_hal *);
244132454Srobertoextern	void ar5211UpdateMibCounters(struct ath_hal *, HAL_MIB_STATS *);
245132454Srobertoextern	void ar5211EnableHwEncryption(struct ath_hal *);
246132454Srobertoextern	void ar5211DisableHwEncryption(struct ath_hal *);
247132454Srobertoextern	HAL_BOOL ar5211SetSlotTime(struct ath_hal *, u_int);
248132454Srobertoextern	u_int ar5211GetSlotTime(struct ath_hal *);
249132454Srobertoextern	HAL_BOOL ar5211SetAckTimeout(struct ath_hal *, u_int);
250132454Srobertoextern	u_int ar5211GetAckTimeout(struct ath_hal *);
251132454Srobertoextern	HAL_BOOL ar5211SetAckCTSRate(struct ath_hal *, u_int);
252132454Srobertoextern	u_int ar5211GetAckCTSRate(struct ath_hal *);
253132454Srobertoextern	HAL_BOOL ar5211SetCTSTimeout(struct ath_hal *, u_int);
25454359Srobertoextern	u_int ar5211GetCTSTimeout(struct ath_hal *);
25582505Srobertoextern	HAL_BOOL ar5211SetSifsTime(struct ath_hal *, u_int);
256132454Srobertoextern	u_int ar5211GetSifsTime(struct ath_hal *);
257132454Srobertoextern  HAL_BOOL ar5211SetDecompMask(struct ath_hal *, uint16_t, int);
258132454Srobertoextern	void ar5211SetCoverageClass(struct ath_hal *, uint8_t, int);
259132454Srobertoextern	uint32_t ar5211GetCurRssi(struct ath_hal *);
260132454Srobertoextern	u_int ar5211GetDefAntenna(struct ath_hal *);
261132454Srobertoextern	void ar5211SetDefAntenna(struct ath_hal *ah, u_int antenna);
262132454Srobertoextern	HAL_ANT_SETTING ar5211GetAntennaSwitch(struct ath_hal *);
263132454Srobertoextern	HAL_BOOL ar5211SetAntennaSwitch(struct ath_hal *, HAL_ANT_SETTING);
264132454Srobertoextern	HAL_STATUS ar5211GetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
265132454Sroberto		uint32_t, uint32_t *);
266132454Srobertoextern	HAL_BOOL ar5211SetCapability(struct ath_hal *, HAL_CAPABILITY_TYPE,
267132454Sroberto		uint32_t, uint32_t, HAL_STATUS *);
268132454Srobertoextern	HAL_BOOL ar5211GetDiagState(struct ath_hal *ah, int request,
269132454Sroberto		const void *args, uint32_t argsize,
270132454Sroberto		void **result, uint32_t *resultsize);
271132454Sroberto
272132454Srobertoextern	u_int ar5211GetKeyCacheSize(struct ath_hal *);
273132454Srobertoextern	HAL_BOOL ar5211IsKeyCacheEntryValid(struct ath_hal *, uint16_t);
274132454Srobertoextern	HAL_BOOL ar5211ResetKeyCacheEntry(struct ath_hal *, uint16_t entry);
27554359Srobertoextern	HAL_BOOL ar5211SetKeyCacheEntry(struct ath_hal *, uint16_t entry,
27654359Sroberto                       const HAL_KEYVAL *, const uint8_t *mac,
27754359Sroberto                       int xorKey);
27882505Srobertoextern	HAL_BOOL ar5211SetKeyCacheEntryMac(struct ath_hal *,
27954359Sroberto			uint16_t, const uint8_t *);
28054359Sroberto
281132454Srobertoextern	HAL_BOOL ar5211SetPowerMode(struct ath_hal *, uint32_t powerRequest,
282132454Sroberto		int setChip);
28354359Srobertoextern	HAL_POWER_MODE ar5211GetPowerMode(struct ath_hal *);
28482505Sroberto
285132454Srobertoextern	void ar5211SetBeaconTimers(struct ath_hal *,
28682505Sroberto		const HAL_BEACON_TIMERS *);
287132454Srobertoextern	void ar5211BeaconInit(struct ath_hal *, uint32_t, uint32_t);
288132454Srobertoextern	void ar5211SetStaBeaconTimers(struct ath_hal *,
289132454Sroberto		const HAL_BEACON_STATE *);
290132454Srobertoextern	void ar5211ResetStaBeaconTimers(struct ath_hal *);
291132454Sroberto
292132454Srobertoextern	HAL_BOOL ar5211IsInterruptPending(struct ath_hal *);
293132454Srobertoextern	HAL_BOOL ar5211GetPendingInterrupts(struct ath_hal *, HAL_INT *);
29454359Srobertoextern	HAL_INT ar5211GetInterrupts(struct ath_hal *);
29582505Srobertoextern	HAL_INT ar5211SetInterrupts(struct ath_hal *, HAL_INT ints);
296132454Sroberto
29754359Srobertoextern	const HAL_RATE_TABLE *ar5211GetRateTable(struct ath_hal *, u_int mode);
29854359Sroberto
29954359Srobertoextern	HAL_BOOL ar5211AniControl(struct ath_hal *, HAL_ANI_CMD, int );
30054359Srobertoextern	void ar5211AniPoll(struct ath_hal *, const HAL_NODE_STATS *, HAL_CHANNEL *);
30154359Srobertoextern	void ar5211MibEvent(struct ath_hal *, const HAL_NODE_STATS *);
30254359Sroberto#endif /* _ATH_AR5211_H_ */
30354359Sroberto