rt2x00reg.h revision 1affa091975e47d50ce6a88e9b1abfe717c2fe27
1/* 2 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> 3 <http://rt2x00.serialmonkey.com> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the 17 Free Software Foundation, Inc., 18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21/* 22 Module: rt2x00 23 Abstract: rt2x00 generic register information. 24 */ 25 26#ifndef RT2X00REG_H 27#define RT2X00REG_H 28 29/* 30 * RX crypto status 31 */ 32enum rx_crypto { 33 RX_CRYPTO_SUCCESS = 0, 34 RX_CRYPTO_FAIL_ICV = 1, 35 RX_CRYPTO_FAIL_MIC = 2, 36 RX_CRYPTO_FAIL_KEY = 3, 37}; 38 39/* 40 * Antenna values 41 */ 42enum antenna { 43 ANTENNA_SW_DIVERSITY = 0, 44 ANTENNA_A = 1, 45 ANTENNA_B = 2, 46 ANTENNA_HW_DIVERSITY = 3, 47}; 48 49/* 50 * Led mode values. 51 */ 52enum led_mode { 53 LED_MODE_DEFAULT = 0, 54 LED_MODE_TXRX_ACTIVITY = 1, 55 LED_MODE_SIGNAL_STRENGTH = 2, 56 LED_MODE_ASUS = 3, 57 LED_MODE_ALPHA = 4, 58}; 59 60/* 61 * TSF sync values 62 */ 63enum tsf_sync { 64 TSF_SYNC_NONE = 0, 65 TSF_SYNC_INFRA = 1, 66 TSF_SYNC_BEACON = 2, 67}; 68 69/* 70 * Device states 71 */ 72enum dev_state { 73 STATE_DEEP_SLEEP = 0, 74 STATE_SLEEP = 1, 75 STATE_STANDBY = 2, 76 STATE_AWAKE = 3, 77 78/* 79 * Additional device states, these values are 80 * not strict since they are not directly passed 81 * into the device. 82 */ 83 STATE_RADIO_ON, 84 STATE_RADIO_OFF, 85 STATE_RADIO_RX_ON, 86 STATE_RADIO_RX_OFF, 87 STATE_RADIO_RX_ON_LINK, 88 STATE_RADIO_RX_OFF_LINK, 89 STATE_RADIO_IRQ_ON, 90 STATE_RADIO_IRQ_OFF, 91}; 92 93/* 94 * IFS backoff values 95 */ 96enum ifs { 97 IFS_BACKOFF = 0, 98 IFS_SIFS = 1, 99 IFS_NEW_BACKOFF = 2, 100 IFS_NONE = 3, 101}; 102 103/* 104 * IFS backoff values for HT devices 105 */ 106enum txop { 107 TXOP_HTTXOP = 0, 108 TXOP_PIFS = 1, 109 TXOP_SIFS = 2, 110 TXOP_BACKOFF = 3, 111}; 112 113/* 114 * Cipher types for hardware encryption 115 */ 116enum cipher { 117 CIPHER_NONE = 0, 118 CIPHER_WEP64 = 1, 119 CIPHER_WEP128 = 2, 120 CIPHER_TKIP = 3, 121 CIPHER_AES = 4, 122/* 123 * The following fields were added by rt61pci and rt73usb. 124 */ 125 CIPHER_CKIP64 = 5, 126 CIPHER_CKIP128 = 6, 127 CIPHER_TKIP_NO_MIC = 7, /* Don't send to device */ 128 129/* 130 * Max cipher type. 131 * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128 132 * are excluded due to limitations in mac80211. 133 */ 134 CIPHER_MAX = 4, 135}; 136 137/* 138 * Rate modulations 139 */ 140enum rate_modulation { 141 RATE_MODE_CCK = 0, 142 RATE_MODE_OFDM = 1, 143 RATE_MODE_HT_MIX = 2, 144 RATE_MODE_HT_GREENFIELD = 3, 145}; 146 147/* 148 * Firmware validation error codes 149 */ 150enum firmware_errors { 151 FW_OK, 152 FW_BAD_CRC, 153 FW_BAD_LENGTH, 154 FW_BAD_VERSION, 155}; 156 157/* 158 * Register handlers. 159 * We store the position of a register field inside a field structure, 160 * This will simplify the process of setting and reading a certain field 161 * inside the register while making sure the process remains byte order safe. 162 */ 163struct rt2x00_field8 { 164 u8 bit_offset; 165 u8 bit_mask; 166}; 167 168struct rt2x00_field16 { 169 u16 bit_offset; 170 u16 bit_mask; 171}; 172 173struct rt2x00_field32 { 174 u32 bit_offset; 175 u32 bit_mask; 176}; 177 178/* 179 * Power of two check, this will check 180 * if the mask that has been given contains and contiguous set of bits. 181 * Note that we cannot use the is_power_of_2() function since this 182 * check must be done at compile-time. 183 */ 184#define is_power_of_two(x) ( !((x) & ((x)-1)) ) 185#define low_bit_mask(x) ( ((x)-1) & ~(x) ) 186#define is_valid_mask(x) is_power_of_two(1LU + (x) + low_bit_mask(x)) 187 188/* 189 * Macros to find first set bit in a variable. 190 * These macros behave the same as the __ffs() functions but 191 * the most important difference that this is done during 192 * compile-time rather then run-time. 193 */ 194#define compile_ffs2(__x) \ 195 __builtin_choose_expr(((__x) & 0x1), 0, 1) 196 197#define compile_ffs4(__x) \ 198 __builtin_choose_expr(((__x) & 0x3), \ 199 (compile_ffs2((__x))), \ 200 (compile_ffs2((__x) >> 2) + 2)) 201 202#define compile_ffs8(__x) \ 203 __builtin_choose_expr(((__x) & 0xf), \ 204 (compile_ffs4((__x))), \ 205 (compile_ffs4((__x) >> 4) + 4)) 206 207#define compile_ffs16(__x) \ 208 __builtin_choose_expr(((__x) & 0xff), \ 209 (compile_ffs8((__x))), \ 210 (compile_ffs8((__x) >> 8) + 8)) 211 212#define compile_ffs32(__x) \ 213 __builtin_choose_expr(((__x) & 0xffff), \ 214 (compile_ffs16((__x))), \ 215 (compile_ffs16((__x) >> 16) + 16)) 216 217/* 218 * This macro will check the requirements for the FIELD{8,16,32} macros 219 * The mask should be a constant non-zero contiguous set of bits which 220 * does not exceed the given typelimit. 221 */ 222#define FIELD_CHECK(__mask, __type) \ 223 BUILD_BUG_ON(!(__mask) || \ 224 !is_valid_mask(__mask) || \ 225 (__mask) != (__type)(__mask)) \ 226 227#define FIELD8(__mask) \ 228({ \ 229 FIELD_CHECK(__mask, u8); \ 230 (struct rt2x00_field8) { \ 231 compile_ffs8(__mask), (__mask) \ 232 }; \ 233}) 234 235#define FIELD16(__mask) \ 236({ \ 237 FIELD_CHECK(__mask, u16); \ 238 (struct rt2x00_field16) { \ 239 compile_ffs16(__mask), (__mask) \ 240 }; \ 241}) 242 243#define FIELD32(__mask) \ 244({ \ 245 FIELD_CHECK(__mask, u32); \ 246 (struct rt2x00_field32) { \ 247 compile_ffs32(__mask), (__mask) \ 248 }; \ 249}) 250 251#define SET_FIELD(__reg, __type, __field, __value)\ 252({ \ 253 typecheck(__type, __field); \ 254 *(__reg) &= ~((__field).bit_mask); \ 255 *(__reg) |= ((__value) << \ 256 ((__field).bit_offset)) & \ 257 ((__field).bit_mask); \ 258}) 259 260#define GET_FIELD(__reg, __type, __field) \ 261({ \ 262 typecheck(__type, __field); \ 263 ((__reg) & ((__field).bit_mask)) >> \ 264 ((__field).bit_offset); \ 265}) 266 267#define rt2x00_set_field32(__reg, __field, __value) \ 268 SET_FIELD(__reg, struct rt2x00_field32, __field, __value) 269#define rt2x00_get_field32(__reg, __field) \ 270 GET_FIELD(__reg, struct rt2x00_field32, __field) 271 272#define rt2x00_set_field16(__reg, __field, __value) \ 273 SET_FIELD(__reg, struct rt2x00_field16, __field, __value) 274#define rt2x00_get_field16(__reg, __field) \ 275 GET_FIELD(__reg, struct rt2x00_field16, __field) 276 277#define rt2x00_set_field8(__reg, __field, __value) \ 278 SET_FIELD(__reg, struct rt2x00_field8, __field, __value) 279#define rt2x00_get_field8(__reg, __field) \ 280 GET_FIELD(__reg, struct rt2x00_field8, __field) 281 282#endif /* RT2X00REG_H */ 283