11e10b93dSalc /*
21e10b93dSalc  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
31e10b93dSalc  * Copyright (c) 2002-2008 Atheros Communications, Inc.
41e10b93dSalc  *
51e10b93dSalc  * Permission to use, copy, modify, and/or distribute this software for any
61e10b93dSalc  * purpose with or without fee is hereby granted, provided that the above
71e10b93dSalc  * copyright notice and this permission notice appear in all copies.
81e10b93dSalc  *
91e10b93dSalc  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
101e10b93dSalc  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
111e10b93dSalc  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
121e10b93dSalc  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
131e10b93dSalc  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
141e10b93dSalc  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
151e10b93dSalc  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
161e10b93dSalc  *
17*f24695abScegger  * $Id: ah_internal.h,v 1.6 2011/03/07 11:25:42 cegger Exp $
181e10b93dSalc  */
191e10b93dSalc #ifndef _ATH_AH_INTERAL_H_
201e10b93dSalc #define _ATH_AH_INTERAL_H_
211e10b93dSalc /*
221e10b93dSalc  * Atheros Device Hardware Access Layer (HAL).
231e10b93dSalc  *
241e10b93dSalc  * Internal definitions.
251e10b93dSalc  */
261e10b93dSalc #define	AH_NULL	0
271e10b93dSalc #define	AH_MIN(a,b)	((a)<(b)?(a):(b))
281e10b93dSalc #define	AH_MAX(a,b)	((a)>(b)?(a):(b))
291e10b93dSalc 
301e10b93dSalc #ifndef NBBY
311e10b93dSalc #define	NBBY	8			/* number of bits/byte */
321e10b93dSalc #endif
331e10b93dSalc 
341e10b93dSalc #ifndef roundup
351e10b93dSalc #define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))  /* to any y */
361e10b93dSalc #endif
371e10b93dSalc #ifndef howmany
381e10b93dSalc #define	howmany(x, y)	(((x)+((y)-1))/(y))
391e10b93dSalc #endif
401e10b93dSalc 
411e10b93dSalc #ifndef offsetof
421e10b93dSalc #define	offsetof(type, field)	((size_t)(&((type *)0)->field))
431e10b93dSalc #endif
441e10b93dSalc 
451e10b93dSalc /*
461e10b93dSalc  * Remove const in a way that keeps the compiler happy.
471e10b93dSalc  * This works for gcc but may require other magic for
481e10b93dSalc  * other compilers (not sure where this should reside).
491e10b93dSalc  * Note that uintptr_t is C99.
501e10b93dSalc  */
511e10b93dSalc #ifndef __DECONST
52a9d4fb0bSalc #define	__DECONST(type, var)	((type)(unsigned long)(const void *)(var))
531e10b93dSalc #endif
541e10b93dSalc 
551e10b93dSalc typedef struct {
561e10b93dSalc 	uint16_t	start;		/* first register */
571e10b93dSalc 	uint16_t	end;		/* ending register or zero */
581e10b93dSalc } HAL_REGRANGE;
591e10b93dSalc 
60*f24695abScegger typedef struct {
61*f24695abScegger 	uint32_t	addr;		/* register address/offset */
62*f24695abScegger 	uint32_t	value;		/* value to write */
63*f24695abScegger } HAL_REGWRITE;
64*f24695abScegger 
651e10b93dSalc /*
661e10b93dSalc  * Transmit power scale factor.
671e10b93dSalc  *
681e10b93dSalc  * NB: This is not public because we want to discourage the use of
691e10b93dSalc  *     scaling; folks should use the tx power limit interface.
701e10b93dSalc  */
711e10b93dSalc typedef enum {
721e10b93dSalc 	HAL_TP_SCALE_MAX	= 0,		/* no scaling (default) */
731e10b93dSalc 	HAL_TP_SCALE_50		= 1,		/* 50% of max (-3 dBm) */
741e10b93dSalc 	HAL_TP_SCALE_25		= 2,		/* 25% of max (-6 dBm) */
751e10b93dSalc 	HAL_TP_SCALE_12		= 3,		/* 12% of max (-9 dBm) */
761e10b93dSalc 	HAL_TP_SCALE_MIN	= 4,		/* min, but still on */
771e10b93dSalc } HAL_TP_SCALE;
781e10b93dSalc 
791e10b93dSalc typedef enum {
801e10b93dSalc  	HAL_CAP_RADAR		= 0,		/* Radar capability */
811e10b93dSalc  	HAL_CAP_AR		= 1,		/* AR capability */
821e10b93dSalc } HAL_PHYDIAG_CAPS;
831e10b93dSalc 
841e10b93dSalc /*
851e10b93dSalc  * Each chip or class of chips registers to offer support.
861e10b93dSalc  */
871e10b93dSalc struct ath_hal_chip {
881e10b93dSalc 	const char	*name;
891e10b93dSalc 	const char	*(*probe)(uint16_t vendorid, uint16_t devid);
901e10b93dSalc 	struct ath_hal	*(*attach)(uint16_t devid, HAL_SOFTC,
911e10b93dSalc 			    HAL_BUS_TAG, HAL_BUS_HANDLE, HAL_STATUS *error);
921e10b93dSalc };
931e10b93dSalc #ifndef AH_CHIP
941e10b93dSalc #define	AH_CHIP(_name, _probe, _attach)				\
95*f24695abScegger static struct ath_hal_chip _name##_chip = {			\
961e10b93dSalc 	.name		= #_name,				\
971e10b93dSalc 	.probe		= _probe,				\
981e10b93dSalc 	.attach		= _attach				\
991e10b93dSalc };								\
100*f24695abScegger OS_DATA_SET(ah_chips, _name##_chip)
1011e10b93dSalc #endif
1021e10b93dSalc 
1031e10b93dSalc /*
1041e10b93dSalc  * Each RF backend registers to offer support; this is mostly
1051e10b93dSalc  * used by multi-chip 5212 solutions.  Single-chip solutions
1061e10b93dSalc  * have a fixed idea about which RF to use.
1071e10b93dSalc  */
1081e10b93dSalc struct ath_hal_rf {
1091e10b93dSalc 	const char	*name;
1101e10b93dSalc 	HAL_BOOL	(*probe)(struct ath_hal *ah);
1111e10b93dSalc 	HAL_BOOL	(*attach)(struct ath_hal *ah, HAL_STATUS *ecode);
1121e10b93dSalc };
1131e10b93dSalc #ifndef AH_RF
1141e10b93dSalc #define	AH_RF(_name, _probe, _attach)				\
115a9d4fb0bSalc static struct ath_hal_rf _name##_rf = {				\
116a9d4fb0bSalc 	.name		= __STRING(_name),			\
1171e10b93dSalc 	.probe		= _probe,				\
1181e10b93dSalc 	.attach		= _attach				\
1191e10b93dSalc };								\
120a9d4fb0bSalc OS_DATA_SET(ah_rfs, _name##_rf)
1211e10b93dSalc #endif
1221e10b93dSalc 
1231e10b93dSalc struct ath_hal_rf *ath_hal_rfprobe(struct ath_hal *ah, HAL_STATUS *ecode);
1241e10b93dSalc 
1251e10b93dSalc /*
1261e10b93dSalc  * Internal form of a HAL_CHANNEL.  Note that the structure
1271e10b93dSalc  * must be defined such that you can cast references to a
1281e10b93dSalc  * HAL_CHANNEL so don't shuffle the first two members.
1291e10b93dSalc  */
1301e10b93dSalc typedef struct {
1311e10b93dSalc 	uint32_t	channelFlags;
1321e10b93dSalc 	uint16_t	channel;	/* NB: must be first for casting */
1331e10b93dSalc 	uint8_t		privFlags;
1341e10b93dSalc 	int8_t		maxRegTxPower;
1351e10b93dSalc 	int8_t		maxTxPower;
1361e10b93dSalc 	int8_t		minTxPower;	/* as above... */
1371e10b93dSalc 
1381e10b93dSalc 	HAL_BOOL	bssSendHere;
1391e10b93dSalc 	uint8_t		gainI;
1401e10b93dSalc 	HAL_BOOL	iqCalValid;
1411e10b93dSalc 	uint8_t		calValid;		/* bitmask of cal types */
1421e10b93dSalc 	int8_t		iCoff;
1431e10b93dSalc 	int8_t		qCoff;
1441e10b93dSalc 	int16_t		rawNoiseFloor;
1451e10b93dSalc 	int16_t		noiseFloorAdjust;
1461e10b93dSalc 	int8_t		antennaMax;
1471e10b93dSalc 	uint32_t	regDmnFlags;		/* Flags for channel use in reg */
1481e10b93dSalc 	uint32_t	conformanceTestLimit;	/* conformance test limit from reg domain */
1491e10b93dSalc 	uint16_t	mainSpur;		/* cached spur value for this cahnnel */
1501e10b93dSalc } HAL_CHANNEL_INTERNAL;
1511e10b93dSalc 
1521e10b93dSalc typedef struct {
1531e10b93dSalc 	uint32_t	halChanSpreadSupport 		: 1,
1541e10b93dSalc 			halSleepAfterBeaconBroken	: 1,
1551e10b93dSalc 			halCompressSupport		: 1,
1561e10b93dSalc 			halBurstSupport			: 1,
1571e10b93dSalc 			halFastFramesSupport		: 1,
1581e10b93dSalc 			halChapTuningSupport		: 1,
1591e10b93dSalc 			halTurboGSupport		: 1,
1601e10b93dSalc 			halTurboPrimeSupport		: 1,
1611e10b93dSalc 			halMicAesCcmSupport		: 1,
1621e10b93dSalc 			halMicCkipSupport		: 1,
1631e10b93dSalc 			halMicTkipSupport		: 1,
1641e10b93dSalc 			halTkipMicTxRxKeySupport	: 1,
1651e10b93dSalc 			halCipherAesCcmSupport		: 1,
1661e10b93dSalc 			halCipherCkipSupport		: 1,
1671e10b93dSalc 			halCipherTkipSupport		: 1,
1681e10b93dSalc 			halPSPollBroken			: 1,
1691e10b93dSalc 			halVEOLSupport			: 1,
1701e10b93dSalc 			halBssIdMaskSupport		: 1,
1711e10b93dSalc 			halMcastKeySrchSupport		: 1,
1721e10b93dSalc 			halTsfAddSupport		: 1,
1731e10b93dSalc 			halChanHalfRate			: 1,
1741e10b93dSalc 			halChanQuarterRate		: 1,
1751e10b93dSalc 			halHTSupport			: 1,
1761e10b93dSalc 			halRfSilentSupport		: 1,
1771e10b93dSalc 			halHwPhyCounterSupport		: 1,
1781e10b93dSalc 			halWowSupport			: 1,
1791e10b93dSalc 			halWowMatchPatternExact		: 1,
1801e10b93dSalc 			halAutoSleepSupport		: 1,
1811e10b93dSalc 			halFastCCSupport		: 1,
1821e10b93dSalc 			halBtCoexSupport		: 1;
1831e10b93dSalc 	uint32_t	halRxStbcSupport		: 1,
1841e10b93dSalc 			halTxStbcSupport		: 1,
1851e10b93dSalc 			halGTTSupport			: 1,
1861e10b93dSalc 			halCSTSupport			: 1,
1871e10b93dSalc 			halRifsRxSupport		: 1,
1881e10b93dSalc 			halRifsTxSupport		: 1,
1891e10b93dSalc 			halExtChanDfsSupport		: 1,
1901e10b93dSalc 			halForcePpmSupport		: 1,
1911e10b93dSalc 			halEnhancedPmSupport		: 1,
192*f24695abScegger 			halMbssidAggrSupport		: 1,
193*f24695abScegger 			halBssidMatchSupport		: 1;
1941e10b93dSalc 	uint32_t	halWirelessModes;
1951e10b93dSalc 	uint16_t	halTotalQueues;
1961e10b93dSalc 	uint16_t	halKeyCacheSize;
1971e10b93dSalc 	uint16_t	halLow5GhzChan, halHigh5GhzChan;
1981e10b93dSalc 	uint16_t	halLow2GhzChan, halHigh2GhzChan;
1991e10b93dSalc 	int		halTstampPrecision;
2001e10b93dSalc 	int		halRtsAggrLimit;
2011e10b93dSalc 	uint8_t		halTxChainMask;
2021e10b93dSalc 	uint8_t		halRxChainMask;
2031e10b93dSalc 	uint8_t		halNumGpioPins;
2041e10b93dSalc 	uint8_t		halNumAntCfg2GHz;
2051e10b93dSalc 	uint8_t		halNumAntCfg5GHz;
206*f24695abScegger 	uint32_t	halIntrMask;
2071e10b93dSalc } HAL_CAPABILITIES;
2081e10b93dSalc 
2091e10b93dSalc /*
2101e10b93dSalc  * The ``private area'' follows immediately after the ``public area''
2111e10b93dSalc  * in the data structure returned by ath_hal_attach.  Private data are
2121e10b93dSalc  * used by device-independent code such as the regulatory domain support.
2131e10b93dSalc  * In general, code within the HAL should never depend on data in the
2141e10b93dSalc  * public area.  Instead any public data needed internally should be
2151e10b93dSalc  * shadowed here.
2161e10b93dSalc  *
2171e10b93dSalc  * When declaring a device-specific ath_hal data structure this structure
2181e10b93dSalc  * is assumed to at the front; e.g.
2191e10b93dSalc  *
2201e10b93dSalc  *	struct ath_hal_5212 {
2211e10b93dSalc  *		struct ath_hal_private	ah_priv;
2221e10b93dSalc  *		...
2231e10b93dSalc  *	};
2241e10b93dSalc  *
2251e10b93dSalc  * It might be better to manage the method pointers in this structure
2261e10b93dSalc  * using an indirect pointer to a read-only data structure but this would
2271e10b93dSalc  * disallow class-style method overriding.
2281e10b93dSalc  */
2291e10b93dSalc struct ath_hal_private {
2301e10b93dSalc 	struct ath_hal	h;			/* public area */
2311e10b93dSalc 
2321e10b93dSalc 	/* NB: all methods go first to simplify initialization */
2331e10b93dSalc 	HAL_BOOL	(*ah_getChannelEdges)(struct ath_hal*,
2341e10b93dSalc 				uint16_t channelFlags,
2351e10b93dSalc 				uint16_t *lowChannel, uint16_t *highChannel);
2361e10b93dSalc 	u_int		(*ah_getWirelessModes)(struct ath_hal*);
2371e10b93dSalc 	HAL_BOOL	(*ah_eepromRead)(struct ath_hal *, u_int off,
2381e10b93dSalc 				uint16_t *data);
2391e10b93dSalc 	HAL_BOOL	(*ah_eepromWrite)(struct ath_hal *, u_int off,
2401e10b93dSalc 				uint16_t data);
241*f24695abScegger 	HAL_BOOL	(*ah_gpioCfgOutput)(struct ath_hal *,
242*f24695abScegger 				uint32_t gpio, HAL_GPIO_MUX_TYPE);
2431e10b93dSalc 	HAL_BOOL	(*ah_gpioCfgInput)(struct ath_hal *, uint32_t gpio);
2441e10b93dSalc 	uint32_t	(*ah_gpioGet)(struct ath_hal *, uint32_t gpio);
2451e10b93dSalc 	HAL_BOOL	(*ah_gpioSet)(struct ath_hal *,
2461e10b93dSalc 				uint32_t gpio, uint32_t val);
2471e10b93dSalc 	void		(*ah_gpioSetIntr)(struct ath_hal*, u_int, uint32_t);
2481e10b93dSalc 	HAL_BOOL	(*ah_getChipPowerLimits)(struct ath_hal *,
2491e10b93dSalc 				HAL_CHANNEL *, uint32_t);
2501e10b93dSalc 	int16_t		(*ah_getNfAdjust)(struct ath_hal *,
2511e10b93dSalc 				const HAL_CHANNEL_INTERNAL*);
2521e10b93dSalc 	void		(*ah_getNoiseFloor)(struct ath_hal *,
2531e10b93dSalc 				int16_t nfarray[]);
2541e10b93dSalc 
2551e10b93dSalc 	void		*ah_eeprom;		/* opaque EEPROM state */
2561e10b93dSalc 	uint16_t	ah_eeversion;		/* EEPROM version */
2571e10b93dSalc 	void		(*ah_eepromDetach)(struct ath_hal *);
2581e10b93dSalc 	HAL_STATUS	(*ah_eepromGet)(struct ath_hal *, int, void *);
2591e10b93dSalc 	HAL_BOOL	(*ah_eepromSet)(struct ath_hal *, int, int);
2601e10b93dSalc 	uint16_t	(*ah_getSpurChan)(struct ath_hal *, int, HAL_BOOL);
2611e10b93dSalc 	HAL_BOOL	(*ah_eepromDiag)(struct ath_hal *, int request,
2621e10b93dSalc 			    const void *args, uint32_t argsize,
2631e10b93dSalc 			    void **result, uint32_t *resultsize);
2641e10b93dSalc 
2651e10b93dSalc 	/*
2661e10b93dSalc 	 * Device revision information.
2671e10b93dSalc 	 */
2681e10b93dSalc 	uint16_t	ah_devid;		/* PCI device ID */
2691e10b93dSalc 	uint16_t	ah_subvendorid;		/* PCI subvendor ID */
2701e10b93dSalc 	uint32_t	ah_macVersion;		/* MAC version id */
2711e10b93dSalc 	uint16_t	ah_macRev;		/* MAC revision */
2721e10b93dSalc 	uint16_t	ah_phyRev;		/* PHY revision */
2731e10b93dSalc 	uint16_t	ah_analog5GhzRev;	/* 2GHz radio revision */
2741e10b93dSalc 	uint16_t	ah_analog2GhzRev;	/* 5GHz radio revision */
27561a10f9cSjmcneill 	uint8_t		ah_ispcie;		/* PCIE, special treatment */
2761e10b93dSalc 
2771e10b93dSalc 
2781e10b93dSalc 	HAL_OPMODE	ah_opmode;		/* operating mode from reset */
2791e10b93dSalc 	HAL_CAPABILITIES ah_caps;		/* device capabilities */
2801e10b93dSalc 	uint32_t	ah_diagreg;		/* user-specified AR_DIAG_SW */
2811e10b93dSalc 	int16_t		ah_powerLimit;		/* tx power cap */
2821e10b93dSalc 	uint16_t	ah_maxPowerLevel;	/* calculated max tx power */
2831e10b93dSalc 	u_int		ah_tpScale;		/* tx power scale factor */
2841e10b93dSalc 	uint32_t	ah_11nCompat;		/* 11n compat controls */
2851e10b93dSalc 
2861e10b93dSalc 	/*
2871e10b93dSalc 	 * State for regulatory domain handling.
2881e10b93dSalc 	 */
2891e10b93dSalc 	HAL_REG_DOMAIN	ah_currentRD;		/* Current regulatory domain */
2901e10b93dSalc 	HAL_CTRY_CODE	ah_countryCode;		/* current country code */
2911e10b93dSalc 	HAL_CHANNEL_INTERNAL ah_channels[256];	/* calculated channel list */
2921e10b93dSalc 	u_int		ah_nchan;		/* valid channels in list */
2931e10b93dSalc 	HAL_CHANNEL_INTERNAL *ah_curchan;	/* current channel */
2941e10b93dSalc 
2951e10b93dSalc 	uint8_t    	ah_coverageClass;   	/* coverage class */
2961e10b93dSalc 	HAL_BOOL    	ah_regdomainUpdate;     /* regdomain is updated? */
2971e10b93dSalc 	/*
2981e10b93dSalc 	 * RF Silent handling; setup according to the EEPROM.
2991e10b93dSalc 	 */
3001e10b93dSalc 	uint16_t	ah_rfsilent;		/* GPIO pin + polarity */
3011e10b93dSalc 	HAL_BOOL	ah_rfkillEnabled;	/* enable/disable RfKill */
3021e10b93dSalc 	/*
3031e10b93dSalc 	 * Diagnostic support for discriminating HIUERR reports.
3041e10b93dSalc 	 */
3051e10b93dSalc 	uint32_t	ah_fatalState[6];	/* AR_ISR+shadow regs */
3061e10b93dSalc 	int		ah_rxornIsFatal;	/* how to treat HAL_INT_RXORN */
3071e10b93dSalc };
3081e10b93dSalc 
3091e10b93dSalc #define	AH_PRIVATE(_ah)	((struct ath_hal_private *)(_ah))
3101e10b93dSalc 
3111e10b93dSalc #define	ath_hal_getChannelEdges(_ah, _cf, _lc, _hc) \
3121e10b93dSalc 	AH_PRIVATE(_ah)->ah_getChannelEdges(_ah, _cf, _lc, _hc)
3131e10b93dSalc #define	ath_hal_getWirelessModes(_ah) \
3141e10b93dSalc 	AH_PRIVATE(_ah)->ah_getWirelessModes(_ah)
3151e10b93dSalc #define	ath_hal_eepromRead(_ah, _off, _data) \
3161e10b93dSalc 	AH_PRIVATE(_ah)->ah_eepromRead(_ah, _off, _data)
3171e10b93dSalc #define	ath_hal_eepromWrite(_ah, _off, _data) \
3181e10b93dSalc 	AH_PRIVATE(_ah)->ah_eepromWrite(_ah, _off, _data)
319*f24695abScegger #define	ath_hal_gpioCfgOutput(_ah, _gpio, _type) \
320*f24695abScegger 	AH_PRIVATE(_ah)->ah_gpioCfgOutput(_ah, _gpio, _type)
3211e10b93dSalc #define	ath_hal_gpioCfgInput(_ah, _gpio) \
3221e10b93dSalc 	AH_PRIVATE(_ah)->ah_gpioCfgInput(_ah, _gpio)
3231e10b93dSalc #define	ath_hal_gpioGet(_ah, _gpio) \
3241e10b93dSalc 	AH_PRIVATE(_ah)->ah_gpioGet(_ah, _gpio)
3251e10b93dSalc #define	ath_hal_gpioSet(_ah, _gpio, _val) \
3261e10b93dSalc 	AH_PRIVATE(_ah)->ah_gpioGet(_ah, _gpio, _val)
3271e10b93dSalc #define	ath_hal_gpioSetIntr(_ah, _gpio, _ilevel) \
3281e10b93dSalc 	AH_PRIVATE(_ah)->ah_gpioSetIntr(_ah, _gpio, _ilevel)
3291e10b93dSalc #define	ath_hal_getpowerlimits(_ah, _chans, _nchan) \
3301e10b93dSalc 	AH_PRIVATE(_ah)->ah_getChipPowerLimits(_ah, _chans, _nchan)
3311e10b93dSalc #define ath_hal_getNfAdjust(_ah, _c) \
3321e10b93dSalc 	AH_PRIVATE(_ah)->ah_getNfAdjust(_ah, _c)
3331e10b93dSalc #define	ath_hal_getNoiseFloor(_ah, _nfArray) \
3341e10b93dSalc 	AH_PRIVATE(_ah)->ah_getNoiseFloor(_ah, _nfArray)
33561a10f9cSjmcneill #define	ath_hal_configPCIE(_ah, _reset) \
33661a10f9cSjmcneill 	(_ah)->ah_configPCIE(_ah, _reset)
33761a10f9cSjmcneill #define	ath_hal_disablePCIE(_ah) \
33861a10f9cSjmcneill 	(_ah)->ah_disablePCIE(_ah)
339*f24695abScegger #define	ath_hal_setInterrupts(_ah, _mask) \
340*f24695abScegger 	(_ah)->ah_setInterrupts(_ah, _mask)
3411e10b93dSalc 
3421e10b93dSalc #define	ath_hal_eepromDetach(_ah)			\
3432b9fcdc9Sdyoung do {							\
3442b9fcdc9Sdyoung 	if (AH_PRIVATE(_ah)->ah_eepromDetach != NULL)	\
3452b9fcdc9Sdyoung 		AH_PRIVATE(_ah)->ah_eepromDetach(_ah);	\
3462b9fcdc9Sdyoung } while (/*CONSTCOND*/0)
3471e10b93dSalc #define	ath_hal_eepromGet(_ah, _param, _val) \
3481e10b93dSalc 	AH_PRIVATE(_ah)->ah_eepromGet(_ah, _param, _val)
3491e10b93dSalc #define	ath_hal_eepromSet(_ah, _param, _val) \
3501e10b93dSalc 	AH_PRIVATE(_ah)->ah_eepromSet(_ah, _param, _val)
3511e10b93dSalc #define	ath_hal_eepromGetFlag(_ah, _param) \
3521e10b93dSalc 	(AH_PRIVATE(_ah)->ah_eepromGet(_ah, _param, AH_NULL) == HAL_OK)
3531e10b93dSalc #define ath_hal_getSpurChan(_ah, _ix, _is2G) \
3541e10b93dSalc 	AH_PRIVATE(_ah)->ah_getSpurChan(_ah, _ix, _is2G)
3551e10b93dSalc #define	ath_hal_eepromDiag(_ah, _request, _a, _asize, _r, _rsize) \
3561e10b93dSalc 	AH_PRIVATE(_ah)->ah_eepromDiag(_ah, _request, _a, _asize,  _r, _rsize)
3571e10b93dSalc 
3581e10b93dSalc #if !defined(_NET_IF_IEEE80211_H_) && !defined(_NET80211__IEEE80211_H_)
3591e10b93dSalc /*
3601e10b93dSalc  * Stuff that would naturally come from _ieee80211.h
3611e10b93dSalc  */
3621e10b93dSalc #define	IEEE80211_ADDR_LEN		6
3631e10b93dSalc 
3641e10b93dSalc #define	IEEE80211_WEP_KEYLEN			5	/* 40bit */
3651e10b93dSalc #define	IEEE80211_WEP_IVLEN			3	/* 24bit */
3661e10b93dSalc #define	IEEE80211_WEP_KIDLEN			1	/* 1 octet */
3671e10b93dSalc #define	IEEE80211_WEP_CRCLEN			4	/* CRC-32 */
3681e10b93dSalc 
3691e10b93dSalc #define	IEEE80211_CRC_LEN			4
3701e10b93dSalc 
3711e10b93dSalc #define	IEEE80211_MTU				1500
3721e10b93dSalc #define	IEEE80211_MAX_LEN			(2300 + IEEE80211_CRC_LEN + \
3731e10b93dSalc     (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN))
3741e10b93dSalc 
3751e10b93dSalc enum {
3761e10b93dSalc 	IEEE80211_T_DS,			/* direct sequence spread spectrum */
3771e10b93dSalc 	IEEE80211_T_FH,			/* frequency hopping */
3781e10b93dSalc 	IEEE80211_T_OFDM,		/* frequency division multiplexing */
3791e10b93dSalc 	IEEE80211_T_TURBO,		/* high rate DS */
3801e10b93dSalc 	IEEE80211_T_HT,			/* HT - full GI */
3811e10b93dSalc };
3821e10b93dSalc #define	IEEE80211_T_CCK	IEEE80211_T_DS	/* more common nomenclatur */
3831e10b93dSalc #endif /* _NET_IF_IEEE80211_H_ */
3841e10b93dSalc 
3851e10b93dSalc /* NB: these are defined privately until XR support is announced */
3861e10b93dSalc enum {
3871e10b93dSalc 	ATHEROS_T_XR	= IEEE80211_T_HT+1,	/* extended range */
3881e10b93dSalc };
3891e10b93dSalc 
3901e10b93dSalc #define HAL_TXQ_USE_LOCKOUT_BKOFF_DIS	0x00000001
3911e10b93dSalc 
3921e10b93dSalc #define INIT_AIFS		2
3931e10b93dSalc #define INIT_CWMIN		15
3941e10b93dSalc #define INIT_CWMIN_11B		31
3951e10b93dSalc #define INIT_CWMAX		1023
3961e10b93dSalc #define INIT_SH_RETRY		10
3971e10b93dSalc #define INIT_LG_RETRY		10
3981e10b93dSalc #define INIT_SSH_RETRY		32
3991e10b93dSalc #define INIT_SLG_RETRY		32
4001e10b93dSalc 
4011e10b93dSalc typedef struct {
4021e10b93dSalc 	uint32_t	tqi_ver;		/* HAL TXQ verson */
4031e10b93dSalc 	HAL_TX_QUEUE	tqi_type;		/* hw queue type*/
4041e10b93dSalc 	HAL_TX_QUEUE_SUBTYPE tqi_subtype;	/* queue subtype, if applicable */
4051e10b93dSalc 	HAL_TX_QUEUE_FLAGS tqi_qflags;		/* queue flags */
4061e10b93dSalc 	uint32_t	tqi_priority;
4071e10b93dSalc 	uint32_t	tqi_aifs;		/* aifs */
4081e10b93dSalc 	uint32_t	tqi_cwmin;		/* cwMin */
4091e10b93dSalc 	uint32_t	tqi_cwmax;		/* cwMax */
4101e10b93dSalc 	uint16_t	tqi_shretry;		/* frame short retry limit */
4111e10b93dSalc 	uint16_t	tqi_lgretry;		/* frame long retry limit */
4121e10b93dSalc 	uint32_t	tqi_cbrPeriod;
4131e10b93dSalc 	uint32_t	tqi_cbrOverflowLimit;
4141e10b93dSalc 	uint32_t	tqi_burstTime;
4151e10b93dSalc 	uint32_t	tqi_readyTime;
4161e10b93dSalc 	uint32_t	tqi_physCompBuf;
4171e10b93dSalc 	uint32_t	tqi_intFlags;		/* flags for internal use */
4181e10b93dSalc } HAL_TX_QUEUE_INFO;
4191e10b93dSalc 
4201e10b93dSalc extern	HAL_BOOL ath_hal_setTxQProps(struct ath_hal *ah,
4211e10b93dSalc 		HAL_TX_QUEUE_INFO *qi, const HAL_TXQ_INFO *qInfo);
4221e10b93dSalc extern	HAL_BOOL ath_hal_getTxQProps(struct ath_hal *ah,
4231e10b93dSalc 		HAL_TXQ_INFO *qInfo, const HAL_TX_QUEUE_INFO *qi);
4241e10b93dSalc 
4251e10b93dSalc typedef enum {
4261e10b93dSalc 	HAL_ANI_PRESENT,			/* is ANI support present */
4271e10b93dSalc 	HAL_ANI_NOISE_IMMUNITY_LEVEL,		/* set level */
4281e10b93dSalc 	HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION,	/* enable/disable */
4291e10b93dSalc 	HAL_ANI_CCK_WEAK_SIGNAL_THR,		/* enable/disable */
4301e10b93dSalc 	HAL_ANI_FIRSTEP_LEVEL,			/* set level */
4311e10b93dSalc 	HAL_ANI_SPUR_IMMUNITY_LEVEL,		/* set level */
4321e10b93dSalc 	HAL_ANI_MODE = 6,	/* 0 => manual, 1 => auto (XXX do not change) */
4331e10b93dSalc 	HAL_ANI_PHYERR_RESET,			/* reset phy error stats */
4341e10b93dSalc } HAL_ANI_CMD;
4351e10b93dSalc 
4361e10b93dSalc #define	HAL_SPUR_VAL_MASK		0x3FFF
4371e10b93dSalc #define	HAL_SPUR_CHAN_WIDTH		87
4381e10b93dSalc #define	HAL_BIN_WIDTH_BASE_100HZ	3125
4391e10b93dSalc #define	HAL_BIN_WIDTH_TURBO_100HZ	6250
4401e10b93dSalc #define	HAL_MAX_BINS_ALLOWED		28
4411e10b93dSalc 
4421e10b93dSalc /*
4431e10b93dSalc  * A    = 5GHZ|OFDM
4441e10b93dSalc  * T    = 5GHZ|OFDM|TURBO
4451e10b93dSalc  *
4461e10b93dSalc  * IS_CHAN_A(T) will return TRUE.  This is probably
4471e10b93dSalc  * not the default behavior we want.  We should migrate to a better mask --
4481e10b93dSalc  * perhaps CHANNEL_ALL.
4491e10b93dSalc  *
4501e10b93dSalc  * For now, IS_CHAN_G() masks itself with CHANNEL_108G.
4511e10b93dSalc  *
4521e10b93dSalc  */
4531e10b93dSalc 
4541e10b93dSalc #define	IS_CHAN_A(_c)	(((_c)->channelFlags & CHANNEL_A) == CHANNEL_A)
4551e10b93dSalc #define	IS_CHAN_B(_c)	(((_c)->channelFlags & CHANNEL_B) == CHANNEL_B)
4561e10b93dSalc #define	IS_CHAN_G(_c)	(((_c)->channelFlags & (CHANNEL_108G|CHANNEL_G)) == CHANNEL_G)
4571e10b93dSalc #define	IS_CHAN_108G(_c)(((_c)->channelFlags & CHANNEL_108G) == CHANNEL_108G)
4581e10b93dSalc #define	IS_CHAN_T(_c)	(((_c)->channelFlags & CHANNEL_T) == CHANNEL_T)
4591e10b93dSalc #define	IS_CHAN_PUREG(_c) \
4601e10b93dSalc 	(((_c)->channelFlags & CHANNEL_PUREG) == CHANNEL_PUREG)
4611e10b93dSalc 
4621e10b93dSalc #define	IS_CHAN_TURBO(_c)	(((_c)->channelFlags & CHANNEL_TURBO) != 0)
4631e10b93dSalc #define	IS_CHAN_CCK(_c)		(((_c)->channelFlags & CHANNEL_CCK) != 0)
4641e10b93dSalc #define	IS_CHAN_OFDM(_c)	(((_c)->channelFlags & CHANNEL_OFDM) != 0)
4651e10b93dSalc #define	IS_CHAN_5GHZ(_c)	(((_c)->channelFlags & CHANNEL_5GHZ) != 0)
4661e10b93dSalc #define	IS_CHAN_2GHZ(_c)	(((_c)->channelFlags & CHANNEL_2GHZ) != 0)
4671e10b93dSalc #define	IS_CHAN_PASSIVE(_c)	(((_c)->channelFlags & CHANNEL_PASSIVE) != 0)
4681e10b93dSalc #define	IS_CHAN_HALF_RATE(_c)	(((_c)->channelFlags & CHANNEL_HALF) != 0)
4691e10b93dSalc #define	IS_CHAN_QUARTER_RATE(_c) (((_c)->channelFlags & CHANNEL_QUARTER) != 0)
4701e10b93dSalc 
4711e10b93dSalc #define	IS_CHAN_IN_PUBLIC_SAFETY_BAND(_c) ((_c) > 4940 && (_c) < 4990)
4721e10b93dSalc 
4731e10b93dSalc #define	CHANNEL_HT40		(CHANNEL_HT40PLUS | CHANNEL_HT40MINUS)
4741e10b93dSalc #define	CHANNEL_HT		(CHANNEL_HT20 | CHANNEL_HT40)
4751e10b93dSalc #define	IS_CHAN_HT(_c)		(((_c)->channelFlags & CHANNEL_HT) != 0)
4761e10b93dSalc #define	IS_CHAN_HT20(_c)	(((_c)->channelFlags & CHANNEL_HT) == CHANNEL_HT20)
4771e10b93dSalc #define	IS_CHAN_HT40(_c)	(((_c)->channelFlags & CHANNEL_HT40) != 0)
4781e10b93dSalc 
4791e10b93dSalc /*
4801e10b93dSalc  * Deduce if the host cpu has big- or litt-endian byte order.
4811e10b93dSalc  */
4821e10b93dSalc static __inline__ int
isBigEndian(void)4831e10b93dSalc isBigEndian(void)
4841e10b93dSalc {
4851e10b93dSalc 	union {
4861e10b93dSalc 		int32_t i;
4871e10b93dSalc 		char c[4];
4881e10b93dSalc 	} u;
4891e10b93dSalc 	u.i = 1;
4901e10b93dSalc 	return (u.c[0] == 0);
4911e10b93dSalc }
4921e10b93dSalc 
4931e10b93dSalc /* unalligned little endian access */
4941e10b93dSalc #define LE_READ_2(p)							\
4951e10b93dSalc 	((uint16_t)							\
4961e10b93dSalc 	 ((((const uint8_t *)(p))[0]    ) | (((const uint8_t *)(p))[1]<< 8)))
4971e10b93dSalc #define LE_READ_4(p)							\
4981e10b93dSalc 	((uint32_t)							\
4991e10b93dSalc 	 ((((const uint8_t *)(p))[0]    ) | (((const uint8_t *)(p))[1]<< 8) |\
5001e10b93dSalc 	  (((const uint8_t *)(p))[2]<<16) | (((const uint8_t *)(p))[3]<<24)))
5011e10b93dSalc 
5021e10b93dSalc /*
5031e10b93dSalc  * Register manipulation macros that expect bit field defines
5041e10b93dSalc  * to follow the convention that an _S suffix is appended for
5051e10b93dSalc  * a shift count, while the field mask has no suffix.
5061e10b93dSalc  */
5071e10b93dSalc #define	SM(_v, _f)	(((_v) << _f##_S) & (_f))
5081e10b93dSalc #define	MS(_v, _f)	(((_v) & (_f)) >> _f##_S)
5091e10b93dSalc #define	OS_REG_RMW_FIELD(_a, _r, _f, _v) \
5101e10b93dSalc 	OS_REG_WRITE(_a, _r, \
5111e10b93dSalc 		(OS_REG_READ(_a, _r) &~ (_f)) | (((_v) << _f##_S) & (_f)))
5121e10b93dSalc #define	OS_REG_SET_BIT(_a, _r, _f) \
5131e10b93dSalc 	OS_REG_WRITE(_a, _r, OS_REG_READ(_a, _r) | (_f))
5141e10b93dSalc #define	OS_REG_CLR_BIT(_a, _r, _f) \
5151e10b93dSalc 	OS_REG_WRITE(_a, _r, OS_REG_READ(_a, _r) &~ (_f))
5161e10b93dSalc 
5171e10b93dSalc /*
5181e10b93dSalc  * Regulatory domain support.
5191e10b93dSalc  */
5201e10b93dSalc 
5211e10b93dSalc /*
5221e10b93dSalc  * Return the max allowed antenna gain based on the current
5231e10b93dSalc  * regulatory domain.
5241e10b93dSalc  */
5251e10b93dSalc extern	u_int ath_hal_getantennareduction(struct ath_hal *,
5261e10b93dSalc 		HAL_CHANNEL *, u_int twiceGain);
5271e10b93dSalc /*
5281e10b93dSalc  * Return the test group for the specific channel based on
5291e10b93dSalc  * the current regulator domain.
5301e10b93dSalc  */
5311e10b93dSalc extern	u_int ath_hal_getctl(struct ath_hal *, HAL_CHANNEL *);
5321e10b93dSalc /*
5331e10b93dSalc  * Return whether or not a noise floor check is required
5341e10b93dSalc  * based on the current regulatory domain for the specified
5351e10b93dSalc  * channel.
5361e10b93dSalc  */
5378aafc997Sreinoud extern	HAL_BOOL ath_hal_getnfcheckrequired(struct ath_hal *, HAL_CHANNEL *);
5381e10b93dSalc 
5391e10b93dSalc /*
5401e10b93dSalc  * Map a public channel definition to the corresponding
5411e10b93dSalc  * internal data structure.  This implicitly specifies
5421e10b93dSalc  * whether or not the specified channel is ok to use
5431e10b93dSalc  * based on the current regulatory domain constraints.
5441e10b93dSalc  */
5451e10b93dSalc extern	HAL_CHANNEL_INTERNAL *ath_hal_checkchannel(struct ath_hal *,
5461e10b93dSalc 		const HAL_CHANNEL *);
5471e10b93dSalc 
5481e10b93dSalc /* system-configurable parameters */
5491e10b93dSalc extern	int ath_hal_dma_beacon_response_time;	/* in TU's */
5501e10b93dSalc extern	int ath_hal_sw_beacon_response_time;	/* in TU's */
5511e10b93dSalc extern	int ath_hal_additional_swba_backoff;	/* in TU's */
5521e10b93dSalc 
5531e10b93dSalc /* wait for the register contents to have the specified value */
5541e10b93dSalc extern	HAL_BOOL ath_hal_wait(struct ath_hal *, u_int reg,
5551e10b93dSalc 		uint32_t mask, uint32_t val);
5561e10b93dSalc 
5571e10b93dSalc /* return the first n bits in val reversed */
5581e10b93dSalc extern	uint32_t ath_hal_reverseBits(uint32_t val, uint32_t n);
5591e10b93dSalc 
5601e10b93dSalc /* printf interfaces */
5611e10b93dSalc extern	void ath_hal_printf(struct ath_hal *, const char*, ...)
5621e10b93dSalc 		__printflike(2,3);
563a9d4fb0bSalc extern	void ath_hal_vprintf(struct ath_hal *, const char*, va_list)
5641e10b93dSalc 		__printflike(2, 0);
5651e10b93dSalc extern	const char* ath_hal_ether_sprintf(const uint8_t *mac);
5661e10b93dSalc 
5671e10b93dSalc /* allocate and free memory */
5681e10b93dSalc extern	void *ath_hal_malloc(size_t);
5691e10b93dSalc extern	void ath_hal_free(void *);
5701e10b93dSalc 
5711e10b93dSalc /* common debugging interfaces */
5721e10b93dSalc #ifdef AH_DEBUG
5731e10b93dSalc #include "ah_debug.h"
5741e10b93dSalc extern	int ath_hal_debug;
5751e10b93dSalc extern	void HALDEBUG(struct ath_hal *ah, u_int mask, const char* fmt, ...)
5761e10b93dSalc 	__printflike(3,4);
5771e10b93dSalc #else
5781e10b93dSalc #define HALDEBUG(_ah, __m, _fmt, ...)
5791e10b93dSalc #endif /* AH_DEBUG */
5801e10b93dSalc 
5811e10b93dSalc /*
5821e10b93dSalc  * Register logging definitions shared with ardecode.
5831e10b93dSalc  */
5841e10b93dSalc #include "ah_decode.h"
5851e10b93dSalc 
5861e10b93dSalc /*
5871e10b93dSalc  * Common assertion interface.  Note: it is a bad idea to generate
5881e10b93dSalc  * an assertion failure for any recoverable event.  Instead catch
5891e10b93dSalc  * the violation and, if possible, fix it up or recover from it; either
5901e10b93dSalc  * with an error return value or a diagnostic messages.  System software
5911e10b93dSalc  * does not panic unless the situation is hopeless.
5921e10b93dSalc  */
5931e10b93dSalc #ifdef AH_ASSERT
5941e10b93dSalc extern	void ath_hal_assert_failed(const char* filename,
5951e10b93dSalc 		int lineno, const char* msg);
5961e10b93dSalc 
5971e10b93dSalc #define	HALASSERT(_x) do {					\
5981e10b93dSalc 	if (!(_x)) {						\
5991e10b93dSalc 		ath_hal_assert_failed(__FILE__, __LINE__, #_x);	\
6001e10b93dSalc 	}							\
6011e10b93dSalc } while (0)
6021e10b93dSalc #else
6031e10b93dSalc #define	HALASSERT(_x)
6041e10b93dSalc #endif /* AH_ASSERT */
6051e10b93dSalc 
6061e10b93dSalc /*
60761a10f9cSjmcneill  * Return the h/w frequency for a channel. This may be
60861a10f9cSjmcneill  * different from ic_freq if this is a GSM device that
60961a10f9cSjmcneill  * takes 2.4GHz frequencies and down-converts them.
61061a10f9cSjmcneill  */
61161a10f9cSjmcneill static OS_INLINE uint16_t
ath_hal_gethwchannel(struct ath_hal * ah,const HAL_CHANNEL_INTERNAL * c)61261a10f9cSjmcneill ath_hal_gethwchannel(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c)
61361a10f9cSjmcneill {
61461a10f9cSjmcneill 	return ath_hal_checkchannel(ah, (const HAL_CHANNEL *)c)->channel;
61561a10f9cSjmcneill }
61661a10f9cSjmcneill 
61761a10f9cSjmcneill /*
6181e10b93dSalc  * Convert between microseconds and core system clocks.
6191e10b93dSalc  */
6201e10b93dSalc extern	u_int ath_hal_mac_clks(struct ath_hal *ah, u_int usecs);
6211e10b93dSalc extern	u_int ath_hal_mac_usec(struct ath_hal *ah, u_int clks);
6221e10b93dSalc 
6231e10b93dSalc /*
6241e10b93dSalc  * Generic get/set capability support.  Each chip overrides
6251e10b93dSalc  * this routine to support chip-specific capabilities.
6261e10b93dSalc  */
6271e10b93dSalc extern	HAL_STATUS ath_hal_getcapability(struct ath_hal *ah,
6281e10b93dSalc 		HAL_CAPABILITY_TYPE type, uint32_t capability,
6291e10b93dSalc 		uint32_t *result);
6301e10b93dSalc extern	HAL_BOOL ath_hal_setcapability(struct ath_hal *ah,
6311e10b93dSalc 		HAL_CAPABILITY_TYPE type, uint32_t capability,
6321e10b93dSalc 		uint32_t setting, HAL_STATUS *status);
6331e10b93dSalc 
6341e10b93dSalc /*
6351e10b93dSalc  * Diagnostic interface.  This is an open-ended interface that
6361e10b93dSalc  * is opaque to applications.  Diagnostic programs use this to
6371e10b93dSalc  * retrieve internal data structures, etc.  There is no guarantee
6381e10b93dSalc  * that calling conventions for calls other than HAL_DIAG_REVS
6391e10b93dSalc  * are stable between HAL releases; a diagnostic application must
6401e10b93dSalc  * use the HAL revision information to deal with ABI/API differences.
6411e10b93dSalc  *
6421e10b93dSalc  * NB: do not renumber these, certain codes are publicly used.
6431e10b93dSalc  */
6441e10b93dSalc enum {
6451e10b93dSalc 	HAL_DIAG_REVS		= 0,	/* MAC/PHY/Radio revs */
6461e10b93dSalc 	HAL_DIAG_EEPROM		= 1,	/* EEPROM contents */
6471e10b93dSalc 	HAL_DIAG_EEPROM_EXP_11A	= 2,	/* EEPROM 5112 power exp for 11a */
6481e10b93dSalc 	HAL_DIAG_EEPROM_EXP_11B	= 3,	/* EEPROM 5112 power exp for 11b */
6491e10b93dSalc 	HAL_DIAG_EEPROM_EXP_11G	= 4,	/* EEPROM 5112 power exp for 11g */
6501e10b93dSalc 	HAL_DIAG_ANI_CURRENT	= 5,	/* ANI current channel state */
6511e10b93dSalc 	HAL_DIAG_ANI_OFDM	= 6,	/* ANI OFDM timing error stats */
6521e10b93dSalc 	HAL_DIAG_ANI_CCK	= 7,	/* ANI CCK timing error stats */
6531e10b93dSalc 	HAL_DIAG_ANI_STATS	= 8,	/* ANI statistics */
6541e10b93dSalc 	HAL_DIAG_RFGAIN		= 9,	/* RfGain GAIN_VALUES */
6551e10b93dSalc 	HAL_DIAG_RFGAIN_CURSTEP	= 10,	/* RfGain GAIN_OPTIMIZATION_STEP */
6561e10b93dSalc 	HAL_DIAG_PCDAC		= 11,	/* PCDAC table */
6571e10b93dSalc 	HAL_DIAG_TXRATES	= 12,	/* Transmit rate table */
6581e10b93dSalc 	HAL_DIAG_REGS		= 13,	/* Registers */
6591e10b93dSalc 	HAL_DIAG_ANI_CMD	= 14,	/* ANI issue command (XXX do not change!) */
6601e10b93dSalc 	HAL_DIAG_SETKEY		= 15,	/* Set keycache backdoor */
6611e10b93dSalc 	HAL_DIAG_RESETKEY	= 16,	/* Reset keycache backdoor */
6621e10b93dSalc 	HAL_DIAG_EEREAD		= 17,	/* Read EEPROM word */
6631e10b93dSalc 	HAL_DIAG_EEWRITE	= 18,	/* Write EEPROM word */
6641e10b93dSalc 	/* 19 was HAL_DIAG_TXCONT, 20-23 were for radar */
6651e10b93dSalc 	HAL_DIAG_REGREAD        = 24,   /* Reg reads */
6661e10b93dSalc 	HAL_DIAG_REGWRITE       = 25,   /* Reg writes */
6671e10b93dSalc 	HAL_DIAG_GET_REGBASE    = 26,   /* Get register base */
6681e10b93dSalc 	HAL_DIAG_RDWRITE	= 27,	/* Write regulatory domain */
6691e10b93dSalc 	HAL_DIAG_RDREAD		= 28,	/* Get regulatory domain */
6701e10b93dSalc 	HAL_DIAG_FATALERR	= 29,	/* Read cached interrupt state */
6711e10b93dSalc 	HAL_DIAG_11NCOMPAT	= 30,	/* 11n compatibility tweaks */
6721e10b93dSalc 	HAL_DIAG_ANI_PARAMS	= 31,	/* ANI noise immunity parameters */
6731e10b93dSalc 	HAL_DIAG_CHECK_HANGS	= 32,	/* check h/w hangs */
6741e10b93dSalc };
6751e10b93dSalc 
6761e10b93dSalc enum {
6771e10b93dSalc     HAL_BB_HANG_DFS		= 0x0001,
6781e10b93dSalc     HAL_BB_HANG_RIFS		= 0x0002,
6791e10b93dSalc     HAL_BB_HANG_RX_CLEAR	= 0x0004,
6801e10b93dSalc     HAL_BB_HANG_UNKNOWN		= 0x0080,
6811e10b93dSalc 
6821e10b93dSalc     HAL_MAC_HANG_SIG1		= 0x0100,
6831e10b93dSalc     HAL_MAC_HANG_SIG2		= 0x0200,
6841e10b93dSalc     HAL_MAC_HANG_UNKNOWN	= 0x8000,
6851e10b93dSalc 
6861e10b93dSalc     HAL_BB_HANGS = HAL_BB_HANG_DFS
6871e10b93dSalc 		 | HAL_BB_HANG_RIFS
6881e10b93dSalc 		 | HAL_BB_HANG_RX_CLEAR
6891e10b93dSalc 		 | HAL_BB_HANG_UNKNOWN,
6901e10b93dSalc     HAL_MAC_HANGS = HAL_MAC_HANG_SIG1
6911e10b93dSalc 		 | HAL_MAC_HANG_SIG2
6921e10b93dSalc 		 | HAL_MAC_HANG_UNKNOWN,
6931e10b93dSalc };
6941e10b93dSalc 
6951e10b93dSalc /*
6961e10b93dSalc  * Device revision information.
6971e10b93dSalc  */
6981e10b93dSalc typedef struct {
6991e10b93dSalc 	uint16_t	ah_devid;		/* PCI device ID */
7001e10b93dSalc 	uint16_t	ah_subvendorid;		/* PCI subvendor ID */
7011e10b93dSalc 	uint32_t	ah_macVersion;		/* MAC version id */
7021e10b93dSalc 	uint16_t	ah_macRev;		/* MAC revision */
7031e10b93dSalc 	uint16_t	ah_phyRev;		/* PHY revision */
7041e10b93dSalc 	uint16_t	ah_analog5GhzRev;	/* 2GHz radio revision */
7051e10b93dSalc 	uint16_t	ah_analog2GhzRev;	/* 5GHz radio revision */
7061e10b93dSalc } HAL_REVS;
7071e10b93dSalc 
7081e10b93dSalc /*
7091e10b93dSalc  * Argument payload for HAL_DIAG_SETKEY.
7101e10b93dSalc  */
7111e10b93dSalc typedef struct {
7121e10b93dSalc 	HAL_KEYVAL	dk_keyval;
7131e10b93dSalc 	uint16_t	dk_keyix;	/* key index */
7141e10b93dSalc 	uint8_t		dk_mac[IEEE80211_ADDR_LEN];
7151e10b93dSalc 	int		dk_xor;		/* XOR key data */
7161e10b93dSalc } HAL_DIAG_KEYVAL;
7171e10b93dSalc 
7181e10b93dSalc /*
7191e10b93dSalc  * Argument payload for HAL_DIAG_EEWRITE.
7201e10b93dSalc  */
7211e10b93dSalc typedef struct {
7221e10b93dSalc 	uint16_t	ee_off;		/* eeprom offset */
7231e10b93dSalc 	uint16_t	ee_data;	/* write data */
7241e10b93dSalc } HAL_DIAG_EEVAL;
7251e10b93dSalc 
7261e10b93dSalc 
7271e10b93dSalc typedef struct {
7281e10b93dSalc 	u_int offset;		/* reg offset */
7291e10b93dSalc 	uint32_t val;		/* reg value  */
7301e10b93dSalc } HAL_DIAG_REGVAL;
7311e10b93dSalc 
7321e10b93dSalc /*
7331e10b93dSalc  * 11n compatibility tweaks.
7341e10b93dSalc  */
7351e10b93dSalc #define	HAL_DIAG_11N_SERVICES	0x00000003
7361e10b93dSalc #define	HAL_DIAG_11N_SERVICES_S	0
7371e10b93dSalc #define	HAL_DIAG_11N_TXSTOMP	0x0000000c
7381e10b93dSalc #define	HAL_DIAG_11N_TXSTOMP_S	2
7391e10b93dSalc 
7401e10b93dSalc typedef struct {
7411e10b93dSalc 	int		maxNoiseImmunityLevel;	/* [0..4] */
7421e10b93dSalc 	int		totalSizeDesired[5];
7431e10b93dSalc 	int		coarseHigh[5];
7441e10b93dSalc 	int		coarseLow[5];
7451e10b93dSalc 	int		firpwr[5];
7461e10b93dSalc 
7471e10b93dSalc 	int		maxSpurImmunityLevel;	/* [0..7] */
7481e10b93dSalc 	int		cycPwrThr1[8];
7491e10b93dSalc 
7501e10b93dSalc 	int		maxFirstepLevel;	/* [0..2] */
7511e10b93dSalc 	int		firstep[3];
7521e10b93dSalc 
7531e10b93dSalc 	uint32_t	ofdmTrigHigh;
7541e10b93dSalc 	uint32_t	ofdmTrigLow;
7551e10b93dSalc 	int32_t		cckTrigHigh;
7561e10b93dSalc 	int32_t		cckTrigLow;
7571e10b93dSalc 	int32_t		rssiThrLow;
7581e10b93dSalc 	int32_t		rssiThrHigh;
7591e10b93dSalc 
7601e10b93dSalc 	int		period;			/* update listen period */
7611e10b93dSalc } HAL_ANI_PARAMS;
7621e10b93dSalc 
7631e10b93dSalc extern	HAL_BOOL ath_hal_getdiagstate(struct ath_hal *ah, int request,
7641e10b93dSalc 			const void *args, uint32_t argsize,
7651e10b93dSalc 			void **result, uint32_t *resultsize);
7661e10b93dSalc 
7671e10b93dSalc /*
7681e10b93dSalc  * Setup a h/w rate table for use.
7691e10b93dSalc  */
7701e10b93dSalc extern	void ath_hal_setupratetable(struct ath_hal *ah, HAL_RATE_TABLE *rt);
7711e10b93dSalc 
7721e10b93dSalc /*
7731e10b93dSalc  * Common routine for implementing getChanNoise api.
7741e10b93dSalc  */
7751e10b93dSalc extern	int16_t ath_hal_getChanNoise(struct ath_hal *ah, HAL_CHANNEL *chan);
7761e10b93dSalc 
7771e10b93dSalc /*
7781e10b93dSalc  * Initialization support.
7791e10b93dSalc  */
7801e10b93dSalc typedef struct {
7811e10b93dSalc 	const uint32_t	*data;
7821e10b93dSalc 	int		rows, cols;
7831e10b93dSalc } HAL_INI_ARRAY;
7841e10b93dSalc 
7851e10b93dSalc #define	HAL_INI_INIT(_ia, _data, _cols) do {			\
7861e10b93dSalc 	(_ia)->data = (const uint32_t *)(_data);		\
7871e10b93dSalc 	(_ia)->rows = sizeof(_data) / sizeof((_data)[0]);	\
7881e10b93dSalc 	(_ia)->cols = (_cols);					\
7891e10b93dSalc } while (0)
7901e10b93dSalc #define	HAL_INI_VAL(_ia, _r, _c) \
7911e10b93dSalc 	((_ia)->data[((_r)*(_ia)->cols) + (_c)])
7921e10b93dSalc 
7931e10b93dSalc /*
7941e10b93dSalc  * OS_DELAY() does a PIO READ on the PCI bus which allows
7951e10b93dSalc  * other cards' DMA reads to complete in the middle of our reset.
7961e10b93dSalc  */
7971e10b93dSalc #define DMA_YIELD(x) do {		\
7981e10b93dSalc 	if ((++(x) % 64) == 0)		\
7991e10b93dSalc 		OS_DELAY(1);		\
8001e10b93dSalc } while (0)
8011e10b93dSalc 
8021e10b93dSalc #define HAL_INI_WRITE_ARRAY(ah, regArray, col, regWr) do {             	\
8031e10b93dSalc 	int r;								\
8041e10b93dSalc 	for (r = 0; r < N(regArray); r++) {				\
8051e10b93dSalc 		OS_REG_WRITE(ah, (regArray)[r][0], (regArray)[r][col]);	\
8061e10b93dSalc 		DMA_YIELD(regWr);					\
8071e10b93dSalc 	}								\
8081e10b93dSalc } while (0)
8091e10b93dSalc 
8101e10b93dSalc #define HAL_INI_WRITE_BANK(ah, regArray, bankData, regWr) do {		\
8111e10b93dSalc 	int r;								\
8121e10b93dSalc 	for (r = 0; r < N(regArray); r++) {				\
8131e10b93dSalc 		OS_REG_WRITE(ah, (regArray)[r][0], (bankData)[r]);	\
8141e10b93dSalc 		DMA_YIELD(regWr);					\
8151e10b93dSalc 	}								\
8161e10b93dSalc } while (0)
8171e10b93dSalc 
8181e10b93dSalc extern	int ath_hal_ini_write(struct ath_hal *ah, const HAL_INI_ARRAY *ia,
8191e10b93dSalc 		int col, int regWr);
8201e10b93dSalc extern	void ath_hal_ini_bank_setup(uint32_t data[], const HAL_INI_ARRAY *ia,
8211e10b93dSalc 		int col);
8221e10b93dSalc extern	int ath_hal_ini_bank_write(struct ath_hal *ah, const HAL_INI_ARRAY *ia,
8231e10b93dSalc 		const uint32_t data[], int regWr);
8241e10b93dSalc 
8251e10b93dSalc #define	WLAN_CTRL_FRAME_SIZE	(2+2+6+4)	/* ACK+FCS */
8261e10b93dSalc #endif /* _ATH_AH_INTERAL_H_ */
827