| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-11-08 16:39:55 +01:00
										 |  |  | 	Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	<http://rt2x00.serialmonkey.com>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  | 	it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | 	the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  | 	(at your option) any later version. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | 	but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
					
						
							|  |  |  | 	GNU General Public License for more details. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | 	along with this program; if not, write to the | 
					
						
							|  |  |  | 	Free Software Foundation, Inc., | 
					
						
							|  |  |  | 	59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | 	Module: rt2x00 | 
					
						
							|  |  |  | 	Abstract: rt2x00 generic register information. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef RT2X00REG_H
 | 
					
						
							|  |  |  | #define RT2X00REG_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 16:37:44 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * RX crypto status | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum rx_crypto { | 
					
						
							|  |  |  | 	RX_CRYPTO_SUCCESS = 0, | 
					
						
							|  |  |  | 	RX_CRYPTO_FAIL_ICV = 1, | 
					
						
							|  |  |  | 	RX_CRYPTO_FAIL_MIC = 2, | 
					
						
							|  |  |  | 	RX_CRYPTO_FAIL_KEY = 3, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Antenna values | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum antenna { | 
					
						
							|  |  |  | 	ANTENNA_SW_DIVERSITY = 0, | 
					
						
							|  |  |  | 	ANTENNA_A = 1, | 
					
						
							|  |  |  | 	ANTENNA_B = 2, | 
					
						
							|  |  |  | 	ANTENNA_HW_DIVERSITY = 3, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Led mode values. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum led_mode { | 
					
						
							|  |  |  | 	LED_MODE_DEFAULT = 0, | 
					
						
							|  |  |  | 	LED_MODE_TXRX_ACTIVITY = 1, | 
					
						
							|  |  |  | 	LED_MODE_SIGNAL_STRENGTH = 2, | 
					
						
							|  |  |  | 	LED_MODE_ASUS = 3, | 
					
						
							|  |  |  | 	LED_MODE_ALPHA = 4, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-06 14:14:29 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * TSF sync values | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum tsf_sync { | 
					
						
							|  |  |  | 	TSF_SYNC_NONE = 0, | 
					
						
							|  |  |  | 	TSF_SYNC_INFRA = 1, | 
					
						
							|  |  |  | 	TSF_SYNC_BEACON = 2, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Device states | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum dev_state { | 
					
						
							|  |  |  | 	STATE_DEEP_SLEEP = 0, | 
					
						
							|  |  |  | 	STATE_SLEEP = 1, | 
					
						
							|  |  |  | 	STATE_STANDBY = 2, | 
					
						
							|  |  |  | 	STATE_AWAKE = 3, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Additional device states, these values are | 
					
						
							|  |  |  |  * not strict since they are not directly passed | 
					
						
							|  |  |  |  * into the device. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	STATE_RADIO_ON, | 
					
						
							|  |  |  | 	STATE_RADIO_OFF, | 
					
						
							|  |  |  | 	STATE_RADIO_RX_ON, | 
					
						
							|  |  |  | 	STATE_RADIO_RX_OFF, | 
					
						
							| 
									
										
										
										
											2008-02-25 23:15:05 +01:00
										 |  |  | 	STATE_RADIO_RX_ON_LINK, | 
					
						
							|  |  |  | 	STATE_RADIO_RX_OFF_LINK, | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	STATE_RADIO_IRQ_ON, | 
					
						
							|  |  |  | 	STATE_RADIO_IRQ_OFF, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * IFS backoff values | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum ifs { | 
					
						
							|  |  |  | 	IFS_BACKOFF = 0, | 
					
						
							|  |  |  | 	IFS_SIFS = 1, | 
					
						
							|  |  |  | 	IFS_NEW_BACKOFF = 2, | 
					
						
							|  |  |  | 	IFS_NONE = 3, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Cipher types for hardware encryption | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum cipher { | 
					
						
							|  |  |  | 	CIPHER_NONE = 0, | 
					
						
							|  |  |  | 	CIPHER_WEP64 = 1, | 
					
						
							|  |  |  | 	CIPHER_WEP128 = 2, | 
					
						
							|  |  |  | 	CIPHER_TKIP = 3, | 
					
						
							|  |  |  | 	CIPHER_AES = 4, | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * The following fields were added by rt61pci and rt73usb. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	CIPHER_CKIP64 = 5, | 
					
						
							|  |  |  | 	CIPHER_CKIP128 = 6, | 
					
						
							| 
									
										
										
										
											2008-08-04 16:37:44 +02:00
										 |  |  | 	CIPHER_TKIP_NO_MIC = 7, /* Don't send to device */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Max cipher type. | 
					
						
							|  |  |  |  * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128 | 
					
						
							|  |  |  |  * are excluded due to limitations in mac80211. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 	CIPHER_MAX = 4, | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-20 10:59:02 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Rate modulations | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum rate_modulation { | 
					
						
							|  |  |  | 	RATE_MODE_CCK = 0, | 
					
						
							|  |  |  | 	RATE_MODE_OFDM = 1, | 
					
						
							|  |  |  | 	RATE_MODE_HT_MIX = 2, | 
					
						
							|  |  |  | 	RATE_MODE_HT_GREENFIELD = 3, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-28 00:33:47 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Firmware validation error codes | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | enum firmware_errors { | 
					
						
							|  |  |  | 	FW_OK, | 
					
						
							|  |  |  | 	FW_BAD_CRC, | 
					
						
							|  |  |  | 	FW_BAD_LENGTH, | 
					
						
							|  |  |  | 	FW_BAD_VERSION, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Register handlers. | 
					
						
							|  |  |  |  * We store the position of a register field inside a field structure, | 
					
						
							|  |  |  |  * This will simplify the process of setting and reading a certain field | 
					
						
							|  |  |  |  * inside the register while making sure the process remains byte order safe. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct rt2x00_field8 { | 
					
						
							|  |  |  | 	u8 bit_offset; | 
					
						
							|  |  |  | 	u8 bit_mask; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct rt2x00_field16 { | 
					
						
							|  |  |  | 	u16 bit_offset; | 
					
						
							|  |  |  | 	u16 bit_mask; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct rt2x00_field32 { | 
					
						
							|  |  |  | 	u32 bit_offset; | 
					
						
							|  |  |  | 	u32 bit_mask; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Power of two check, this will check | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  |  * if the mask that has been given contains and contiguous set of bits. | 
					
						
							|  |  |  |  * Note that we cannot use the is_power_of_2() function since this | 
					
						
							|  |  |  |  * check must be done at compile-time. | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  |  */ | 
					
						
							|  |  |  | #define is_power_of_two(x)	( !((x) & ((x)-1)) )
 | 
					
						
							|  |  |  | #define low_bit_mask(x)		( ((x)-1) & ~(x) )
 | 
					
						
							| 
									
										
										
										
											2008-09-01 14:47:19 +03:00
										 |  |  | #define is_valid_mask(x)	is_power_of_two(1LU + (x) + low_bit_mask(x))
 | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-07-17 21:39:19 +02:00
										 |  |  |  * Macros to find first set bit in a variable. | 
					
						
							|  |  |  |  * These macros behave the same as the __ffs() functions but | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  |  * the most important difference that this is done during | 
					
						
							|  |  |  |  * compile-time rather then run-time. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define compile_ffs2(__x) \
 | 
					
						
							| 
									
										
										
										
											2008-06-06 22:58:29 +02:00
										 |  |  | 	__builtin_choose_expr(((__x) & 0x1), 0, 1) | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define compile_ffs4(__x) \
 | 
					
						
							| 
									
										
										
										
											2008-06-06 22:58:29 +02:00
										 |  |  | 	__builtin_choose_expr(((__x) & 0x3), \ | 
					
						
							|  |  |  | 			      (compile_ffs2((__x))), \ | 
					
						
							|  |  |  | 			      (compile_ffs2((__x) >> 2) + 2)) | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define compile_ffs8(__x) \
 | 
					
						
							| 
									
										
										
										
											2008-06-06 22:58:29 +02:00
										 |  |  | 	__builtin_choose_expr(((__x) & 0xf), \ | 
					
						
							|  |  |  | 			      (compile_ffs4((__x))), \ | 
					
						
							|  |  |  | 			      (compile_ffs4((__x) >> 4) + 4)) | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define compile_ffs16(__x) \
 | 
					
						
							| 
									
										
										
										
											2008-06-06 22:58:29 +02:00
										 |  |  | 	__builtin_choose_expr(((__x) & 0xff), \ | 
					
						
							|  |  |  | 			      (compile_ffs8((__x))), \ | 
					
						
							|  |  |  | 			      (compile_ffs8((__x) >> 8) + 8)) | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define compile_ffs32(__x) \
 | 
					
						
							| 
									
										
										
										
											2008-06-06 22:58:29 +02:00
										 |  |  | 	__builtin_choose_expr(((__x) & 0xffff), \ | 
					
						
							|  |  |  | 			      (compile_ffs16((__x))), \ | 
					
						
							|  |  |  | 			      (compile_ffs16((__x) >> 16) + 16)) | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * This macro will check the requirements for the FIELD{8,16,32} macros | 
					
						
							|  |  |  |  * The mask should be a constant non-zero contiguous set of bits which | 
					
						
							|  |  |  |  * does not exceed the given typelimit. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define FIELD_CHECK(__mask, __type)			\
 | 
					
						
							| 
									
										
										
										
											2008-09-01 14:47:19 +03:00
										 |  |  | 	BUILD_BUG_ON(!(__mask) ||			\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 		     !is_valid_mask(__mask) ||		\ | 
					
						
							|  |  |  | 		     (__mask) != (__type)(__mask))	\ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | #define FIELD8(__mask)				\
 | 
					
						
							|  |  |  | ({						\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 	FIELD_CHECK(__mask, u8);		\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	(struct rt2x00_field8) {		\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 		compile_ffs8(__mask), (__mask)	\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	};					\ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FIELD16(__mask)				\
 | 
					
						
							|  |  |  | ({						\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 	FIELD_CHECK(__mask, u16);		\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	(struct rt2x00_field16) {		\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 		compile_ffs16(__mask), (__mask)	\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	};					\ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FIELD32(__mask)				\
 | 
					
						
							|  |  |  | ({						\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 	FIELD_CHECK(__mask, u32);		\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	(struct rt2x00_field32) {		\ | 
					
						
							| 
									
										
										
										
											2008-06-03 22:45:35 +02:00
										 |  |  | 		compile_ffs32(__mask), (__mask)	\ | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 	};					\ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-03 20:29:43 +02:00
										 |  |  | #define SET_FIELD(__reg, __type, __field, __value)\
 | 
					
						
							|  |  |  | ({						\ | 
					
						
							|  |  |  | 	typecheck(__type, __field);		\ | 
					
						
							|  |  |  | 	*(__reg) &= ~((__field).bit_mask);	\ | 
					
						
							|  |  |  | 	*(__reg) |= ((__value) <<		\ | 
					
						
							|  |  |  | 	    ((__field).bit_offset)) &		\ | 
					
						
							|  |  |  | 	    ((__field).bit_mask);		\ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GET_FIELD(__reg, __type, __field)	\
 | 
					
						
							|  |  |  | ({						\ | 
					
						
							|  |  |  | 	typecheck(__type, __field);		\ | 
					
						
							|  |  |  | 	((__reg) & ((__field).bit_mask)) >>	\ | 
					
						
							|  |  |  | 	    ((__field).bit_offset);		\ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define rt2x00_set_field32(__reg, __field, __value) \
 | 
					
						
							|  |  |  | 	SET_FIELD(__reg, struct rt2x00_field32, __field, __value) | 
					
						
							|  |  |  | #define rt2x00_get_field32(__reg, __field) \
 | 
					
						
							|  |  |  | 	GET_FIELD(__reg, struct rt2x00_field32, __field) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define rt2x00_set_field16(__reg, __field, __value) \
 | 
					
						
							|  |  |  | 	SET_FIELD(__reg, struct rt2x00_field16, __field, __value) | 
					
						
							|  |  |  | #define rt2x00_get_field16(__reg, __field) \
 | 
					
						
							|  |  |  | 	GET_FIELD(__reg, struct rt2x00_field16, __field) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define rt2x00_set_field8(__reg, __field, __value) \
 | 
					
						
							|  |  |  | 	SET_FIELD(__reg, struct rt2x00_field8, __field, __value) | 
					
						
							|  |  |  | #define rt2x00_get_field8(__reg, __field) \
 | 
					
						
							|  |  |  | 	GET_FIELD(__reg, struct rt2x00_field8, __field) | 
					
						
							| 
									
										
										
										
											2007-09-25 17:57:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif /* RT2X00REG_H */
 |