2         Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
 
   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, write to the
 
  17         Free Software Foundation, Inc.,
 
  18         59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
  23         Abstract: rt2x00 generic register information.
 
  33         RX_CRYPTO_SUCCESS = 0,
 
  34         RX_CRYPTO_FAIL_ICV = 1,
 
  35         RX_CRYPTO_FAIL_MIC = 2,
 
  36         RX_CRYPTO_FAIL_KEY = 3,
 
  43         ANTENNA_SW_DIVERSITY = 0,
 
  46         ANTENNA_HW_DIVERSITY = 3,
 
  54         LED_MODE_TXRX_ACTIVITY = 1,
 
  55         LED_MODE_SIGNAL_STRENGTH = 2,
 
  79  * Additional device states, these values are
 
  80  * not strict since they are not directly passed
 
  87         STATE_RADIO_RX_ON_LINK,
 
  88         STATE_RADIO_RX_OFF_LINK,
 
 104  * Cipher types for hardware encryption
 
 113  * The following fields were added by rt61pci and rt73usb.
 
 117         CIPHER_TKIP_NO_MIC = 7, /* Don't send to device */
 
 121  * Note that CIPHER_NONE isn't counted, and CKIP64 and CKIP128
 
 122  * are excluded due to limitations in mac80211.
 
 129  * We store the position of a register field inside a field structure,
 
 130  * This will simplify the process of setting and reading a certain field
 
 131  * inside the register while making sure the process remains byte order safe.
 
 133 struct rt2x00_field8 {
 
 138 struct rt2x00_field16 {
 
 143 struct rt2x00_field32 {
 
 149  * Power of two check, this will check
 
 150  * if the mask that has been given contains and contiguous set of bits.
 
 151  * Note that we cannot use the is_power_of_2() function since this
 
 152  * check must be done at compile-time.
 
 154 #define is_power_of_two(x)      ( !((x) & ((x)-1)) )
 
 155 #define low_bit_mask(x)         ( ((x)-1) & ~(x) )
 
 156 #define is_valid_mask(x)        is_power_of_two(1LU + (x) + low_bit_mask(x))
 
 159  * Macro's to find first set bit in a variable.
 
 160  * These macro's behaves the same as the __ffs() function with
 
 161  * the most important difference that this is done during
 
 162  * compile-time rather then run-time.
 
 164 #define compile_ffs2(__x) \
 
 165         __builtin_choose_expr(((__x) & 0x1), 0, 1)
 
 167 #define compile_ffs4(__x) \
 
 168         __builtin_choose_expr(((__x) & 0x3), \
 
 169                               (compile_ffs2((__x))), \
 
 170                               (compile_ffs2((__x) >> 2) + 2))
 
 172 #define compile_ffs8(__x) \
 
 173         __builtin_choose_expr(((__x) & 0xf), \
 
 174                               (compile_ffs4((__x))), \
 
 175                               (compile_ffs4((__x) >> 4) + 4))
 
 177 #define compile_ffs16(__x) \
 
 178         __builtin_choose_expr(((__x) & 0xff), \
 
 179                               (compile_ffs8((__x))), \
 
 180                               (compile_ffs8((__x) >> 8) + 8))
 
 182 #define compile_ffs32(__x) \
 
 183         __builtin_choose_expr(((__x) & 0xffff), \
 
 184                               (compile_ffs16((__x))), \
 
 185                               (compile_ffs16((__x) >> 16) + 16))
 
 188  * This macro will check the requirements for the FIELD{8,16,32} macros
 
 189  * The mask should be a constant non-zero contiguous set of bits which
 
 190  * does not exceed the given typelimit.
 
 192 #define FIELD_CHECK(__mask, __type)                     \
 
 193         BUILD_BUG_ON(!(__mask) ||                       \
 
 194                      !is_valid_mask(__mask) ||          \
 
 195                      (__mask) != (__type)(__mask))      \
 
 197 #define FIELD8(__mask)                          \
 
 199         FIELD_CHECK(__mask, u8);                \
 
 200         (struct rt2x00_field8) {                \
 
 201                 compile_ffs8(__mask), (__mask)  \
 
 205 #define FIELD16(__mask)                         \
 
 207         FIELD_CHECK(__mask, u16);               \
 
 208         (struct rt2x00_field16) {               \
 
 209                 compile_ffs16(__mask), (__mask) \
 
 213 #define FIELD32(__mask)                         \
 
 215         FIELD_CHECK(__mask, u32);               \
 
 216         (struct rt2x00_field32) {               \
 
 217                 compile_ffs32(__mask), (__mask) \
 
 221 #define SET_FIELD(__reg, __type, __field, __value)\
 
 223         typecheck(__type, __field);             \
 
 224         *(__reg) &= ~((__field).bit_mask);      \
 
 225         *(__reg) |= ((__value) <<               \
 
 226             ((__field).bit_offset)) &           \
 
 227             ((__field).bit_mask);               \
 
 230 #define GET_FIELD(__reg, __type, __field)       \
 
 232         typecheck(__type, __field);             \
 
 233         ((__reg) & ((__field).bit_mask)) >>     \
 
 234             ((__field).bit_offset);             \
 
 237 #define rt2x00_set_field32(__reg, __field, __value) \
 
 238         SET_FIELD(__reg, struct rt2x00_field32, __field, __value)
 
 239 #define rt2x00_get_field32(__reg, __field) \
 
 240         GET_FIELD(__reg, struct rt2x00_field32, __field)
 
 242 #define rt2x00_set_field16(__reg, __field, __value) \
 
 243         SET_FIELD(__reg, struct rt2x00_field16, __field, __value)
 
 244 #define rt2x00_get_field16(__reg, __field) \
 
 245         GET_FIELD(__reg, struct rt2x00_field16, __field)
 
 247 #define rt2x00_set_field8(__reg, __field, __value) \
 
 248         SET_FIELD(__reg, struct rt2x00_field8, __field, __value)
 
 249 #define rt2x00_get_field8(__reg, __field) \
 
 250         GET_FIELD(__reg, struct rt2x00_field8, __field)
 
 252 #endif /* RT2X00REG_H */