rt2x00reg.h 5.5 KB

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