2 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3 <http://rt2x00.serialmonkey.com>
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 Abstract: rt2x00 generic register information.
31 RX_CRYPTO_SUCCESS
= 0,
32 RX_CRYPTO_FAIL_ICV
= 1,
33 RX_CRYPTO_FAIL_MIC
= 2,
34 RX_CRYPTO_FAIL_KEY
= 3,
41 ANTENNA_SW_DIVERSITY
= 0,
44 ANTENNA_HW_DIVERSITY
= 3,
52 LED_MODE_TXRX_ACTIVITY
= 1,
53 LED_MODE_SIGNAL_STRENGTH
= 2,
78 * Additional device states, these values are
79 * not strict since they are not directly passed
99 * IFS backoff values for HT devices
109 * Cipher types for hardware encryption
118 * The following fields were added by rt61pci and rt73usb.
122 CIPHER_TKIP_NO_MIC
= 7, /* Don't send to device */
126 * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128
127 * are excluded due to limitations in mac80211.
135 enum rate_modulation
{
138 RATE_MODE_HT_MIX
= 2,
139 RATE_MODE_HT_GREENFIELD
= 3,
143 * Firmware validation error codes
145 enum firmware_errors
{
154 * We store the position of a register field inside a field structure,
155 * This will simplify the process of setting and reading a certain field
156 * inside the register while making sure the process remains byte order safe.
158 struct rt2x00_field8
{
163 struct rt2x00_field16
{
168 struct rt2x00_field32
{
174 * Power of two check, this will check
175 * if the mask that has been given contains and contiguous set of bits.
176 * Note that we cannot use the is_power_of_2() function since this
177 * check must be done at compile-time.
179 #define is_power_of_two(x) ( !((x) & ((x)-1)) )
180 #define low_bit_mask(x) ( ((x)-1) & ~(x) )
181 #define is_valid_mask(x) is_power_of_two(1LU + (x) + low_bit_mask(x))
184 * Macros to find first set bit in a variable.
185 * These macros behave the same as the __ffs() functions but
186 * the most important difference that this is done during
187 * compile-time rather then run-time.
189 #define compile_ffs2(__x) \
190 __builtin_choose_expr(((__x) & 0x1), 0, 1)
192 #define compile_ffs4(__x) \
193 __builtin_choose_expr(((__x) & 0x3), \
194 (compile_ffs2((__x))), \
195 (compile_ffs2((__x) >> 2) + 2))
197 #define compile_ffs8(__x) \
198 __builtin_choose_expr(((__x) & 0xf), \
199 (compile_ffs4((__x))), \
200 (compile_ffs4((__x) >> 4) + 4))
202 #define compile_ffs16(__x) \
203 __builtin_choose_expr(((__x) & 0xff), \
204 (compile_ffs8((__x))), \
205 (compile_ffs8((__x) >> 8) + 8))
207 #define compile_ffs32(__x) \
208 __builtin_choose_expr(((__x) & 0xffff), \
209 (compile_ffs16((__x))), \
210 (compile_ffs16((__x) >> 16) + 16))
213 * This macro will check the requirements for the FIELD{8,16,32} macros
214 * The mask should be a constant non-zero contiguous set of bits which
215 * does not exceed the given typelimit.
217 #define FIELD_CHECK(__mask, __type) \
218 BUILD_BUG_ON(!(__mask) || \
219 !is_valid_mask(__mask) || \
220 (__mask) != (__type)(__mask)) \
222 #define FIELD8(__mask) \
224 FIELD_CHECK(__mask, u8); \
225 (struct rt2x00_field8) { \
226 compile_ffs8(__mask), (__mask) \
230 #define FIELD16(__mask) \
232 FIELD_CHECK(__mask, u16); \
233 (struct rt2x00_field16) { \
234 compile_ffs16(__mask), (__mask) \
238 #define FIELD32(__mask) \
240 FIELD_CHECK(__mask, u32); \
241 (struct rt2x00_field32) { \
242 compile_ffs32(__mask), (__mask) \
246 #define SET_FIELD(__reg, __type, __field, __value)\
248 typecheck(__type, __field); \
249 *(__reg) &= ~((__field).bit_mask); \
250 *(__reg) |= ((__value) << \
251 ((__field).bit_offset)) & \
252 ((__field).bit_mask); \
255 #define GET_FIELD(__reg, __type, __field) \
257 typecheck(__type, __field); \
258 ((__reg) & ((__field).bit_mask)) >> \
259 ((__field).bit_offset); \
262 #define rt2x00_set_field32(__reg, __field, __value) \
263 SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
264 #define rt2x00_get_field32(__reg, __field) \
265 GET_FIELD(__reg, struct rt2x00_field32, __field)
267 #define rt2x00_set_field16(__reg, __field, __value) \
268 SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
269 #define rt2x00_get_field16(__reg, __field) \
270 GET_FIELD(__reg, struct rt2x00_field16, __field)
272 #define rt2x00_set_field8(__reg, __field, __value) \
273 SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
274 #define rt2x00_get_field8(__reg, __field) \
275 GET_FIELD(__reg, struct rt2x00_field8, __field)
277 #endif /* RT2X00REG_H */