rt2x00reg.h 6.3 KB

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