rt2x00reg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
  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. * TX result flags.
  25. */
  26. enum TX_STATUS {
  27. TX_SUCCESS = 0,
  28. TX_SUCCESS_RETRY = 1,
  29. TX_FAIL_RETRY = 2,
  30. TX_FAIL_INVALID = 3,
  31. TX_FAIL_OTHER = 4,
  32. };
  33. /*
  34. * Antenna values
  35. */
  36. enum antenna {
  37. ANTENNA_SW_DIVERSITY = 0,
  38. ANTENNA_A = 1,
  39. ANTENNA_B = 2,
  40. ANTENNA_HW_DIVERSITY = 3,
  41. };
  42. /*
  43. * Led mode values.
  44. */
  45. enum led_mode {
  46. LED_MODE_DEFAULT = 0,
  47. LED_MODE_TXRX_ACTIVITY = 1,
  48. LED_MODE_SIGNAL_STRENGTH = 2,
  49. LED_MODE_ASUS = 3,
  50. LED_MODE_ALPHA = 4,
  51. };
  52. /*
  53. * Device states
  54. */
  55. enum dev_state {
  56. STATE_DEEP_SLEEP = 0,
  57. STATE_SLEEP = 1,
  58. STATE_STANDBY = 2,
  59. STATE_AWAKE = 3,
  60. /*
  61. * Additional device states, these values are
  62. * not strict since they are not directly passed
  63. * into the device.
  64. */
  65. STATE_RADIO_ON,
  66. STATE_RADIO_OFF,
  67. STATE_RADIO_RX_ON,
  68. STATE_RADIO_RX_OFF,
  69. STATE_RADIO_IRQ_ON,
  70. STATE_RADIO_IRQ_OFF,
  71. };
  72. /*
  73. * IFS backoff values
  74. */
  75. enum ifs {
  76. IFS_BACKOFF = 0,
  77. IFS_SIFS = 1,
  78. IFS_NEW_BACKOFF = 2,
  79. IFS_NONE = 3,
  80. };
  81. /*
  82. * Cipher types for hardware encryption
  83. */
  84. enum cipher {
  85. CIPHER_NONE = 0,
  86. CIPHER_WEP64 = 1,
  87. CIPHER_WEP128 = 2,
  88. CIPHER_TKIP = 3,
  89. CIPHER_AES = 4,
  90. /*
  91. * The following fields were added by rt61pci and rt73usb.
  92. */
  93. CIPHER_CKIP64 = 5,
  94. CIPHER_CKIP128 = 6,
  95. CIPHER_TKIP_NO_MIC = 7,
  96. };
  97. /*
  98. * Register handlers.
  99. * We store the position of a register field inside a field structure,
  100. * This will simplify the process of setting and reading a certain field
  101. * inside the register while making sure the process remains byte order safe.
  102. */
  103. struct rt2x00_field8 {
  104. u8 bit_offset;
  105. u8 bit_mask;
  106. };
  107. struct rt2x00_field16 {
  108. u16 bit_offset;
  109. u16 bit_mask;
  110. };
  111. struct rt2x00_field32 {
  112. u32 bit_offset;
  113. u32 bit_mask;
  114. };
  115. /*
  116. * Power of two check, this will check
  117. * if the mask that has been given contains
  118. * and contiguous set of bits.
  119. */
  120. #define is_power_of_two(x) ( !((x) & ((x)-1)) )
  121. #define low_bit_mask(x) ( ((x)-1) & ~(x) )
  122. #define is_valid_mask(x) is_power_of_two(1 + (x) + low_bit_mask(x))
  123. #define FIELD8(__mask) \
  124. ({ \
  125. BUILD_BUG_ON(!(__mask) || \
  126. !is_valid_mask(__mask) || \
  127. (__mask) != (u8)(__mask)); \
  128. (struct rt2x00_field8) { \
  129. __ffs(__mask), (__mask) \
  130. }; \
  131. })
  132. #define FIELD16(__mask) \
  133. ({ \
  134. BUILD_BUG_ON(!(__mask) || \
  135. !is_valid_mask(__mask) || \
  136. (__mask) != (u16)(__mask));\
  137. (struct rt2x00_field16) { \
  138. __ffs(__mask), (__mask) \
  139. }; \
  140. })
  141. #define FIELD32(__mask) \
  142. ({ \
  143. BUILD_BUG_ON(!(__mask) || \
  144. !is_valid_mask(__mask) || \
  145. (__mask) != (u32)(__mask));\
  146. (struct rt2x00_field32) { \
  147. __ffs(__mask), (__mask) \
  148. }; \
  149. })
  150. static inline void rt2x00_set_field32(u32 *reg,
  151. const struct rt2x00_field32 field,
  152. const u32 value)
  153. {
  154. *reg &= ~(field.bit_mask);
  155. *reg |= (value << field.bit_offset) & field.bit_mask;
  156. }
  157. static inline u32 rt2x00_get_field32(const u32 reg,
  158. const struct rt2x00_field32 field)
  159. {
  160. return (reg & field.bit_mask) >> field.bit_offset;
  161. }
  162. static inline void rt2x00_set_field16(u16 *reg,
  163. const struct rt2x00_field16 field,
  164. const u16 value)
  165. {
  166. *reg &= ~(field.bit_mask);
  167. *reg |= (value << field.bit_offset) & field.bit_mask;
  168. }
  169. static inline u16 rt2x00_get_field16(const u16 reg,
  170. const struct rt2x00_field16 field)
  171. {
  172. return (reg & field.bit_mask) >> field.bit_offset;
  173. }
  174. static inline void rt2x00_set_field8(u8 *reg,
  175. const struct rt2x00_field8 field,
  176. const u8 value)
  177. {
  178. *reg &= ~(field.bit_mask);
  179. *reg |= (value << field.bit_offset) & field.bit_mask;
  180. }
  181. static inline u8 rt2x00_get_field8(const u8 reg,
  182. const struct rt2x00_field8 field)
  183. {
  184. return (reg & field.bit_mask) >> field.bit_offset;
  185. }
  186. /*
  187. * Device specific rate value.
  188. * We will have to create the device specific rate value
  189. * passed to the ieee80211 kernel. We need to make it a consist of
  190. * multiple fields because we want to store more then 1 device specific
  191. * values inside the value.
  192. * 1 - rate, stored as 100 kbit/s.
  193. * 2 - preamble, short_preamble enabled flag.
  194. * 3 - MASK_RATE, which rates are enabled in this mode, this mask
  195. * corresponds with the TX register format for the current device.
  196. * 4 - plcp, 802.11b rates are device specific,
  197. * 802.11g rates are set according to the ieee802.11a-1999 p.14.
  198. * The bit to enable preamble is set in a seperate define.
  199. */
  200. #define DEV_RATE FIELD32(0x000007ff)
  201. #define DEV_PREAMBLE FIELD32(0x00000800)
  202. #define DEV_RATEMASK FIELD32(0x00fff000)
  203. #define DEV_PLCP FIELD32(0xff000000)
  204. /*
  205. * Bitfields
  206. */
  207. #define DEV_RATEBIT_1MB ( 1 << 0 )
  208. #define DEV_RATEBIT_2MB ( 1 << 1 )
  209. #define DEV_RATEBIT_5_5MB ( 1 << 2 )
  210. #define DEV_RATEBIT_11MB ( 1 << 3 )
  211. #define DEV_RATEBIT_6MB ( 1 << 4 )
  212. #define DEV_RATEBIT_9MB ( 1 << 5 )
  213. #define DEV_RATEBIT_12MB ( 1 << 6 )
  214. #define DEV_RATEBIT_18MB ( 1 << 7 )
  215. #define DEV_RATEBIT_24MB ( 1 << 8 )
  216. #define DEV_RATEBIT_36MB ( 1 << 9 )
  217. #define DEV_RATEBIT_48MB ( 1 << 10 )
  218. #define DEV_RATEBIT_54MB ( 1 << 11 )
  219. /*
  220. * Bitmasks for DEV_RATEMASK
  221. */
  222. #define DEV_RATEMASK_1MB ( (DEV_RATEBIT_1MB << 1) -1 )
  223. #define DEV_RATEMASK_2MB ( (DEV_RATEBIT_2MB << 1) -1 )
  224. #define DEV_RATEMASK_5_5MB ( (DEV_RATEBIT_5_5MB << 1) -1 )
  225. #define DEV_RATEMASK_11MB ( (DEV_RATEBIT_11MB << 1) -1 )
  226. #define DEV_RATEMASK_6MB ( (DEV_RATEBIT_6MB << 1) -1 )
  227. #define DEV_RATEMASK_9MB ( (DEV_RATEBIT_9MB << 1) -1 )
  228. #define DEV_RATEMASK_12MB ( (DEV_RATEBIT_12MB << 1) -1 )
  229. #define DEV_RATEMASK_18MB ( (DEV_RATEBIT_18MB << 1) -1 )
  230. #define DEV_RATEMASK_24MB ( (DEV_RATEBIT_24MB << 1) -1 )
  231. #define DEV_RATEMASK_36MB ( (DEV_RATEBIT_36MB << 1) -1 )
  232. #define DEV_RATEMASK_48MB ( (DEV_RATEBIT_48MB << 1) -1 )
  233. #define DEV_RATEMASK_54MB ( (DEV_RATEBIT_54MB << 1) -1 )
  234. /*
  235. * Bitmask groups of bitrates
  236. */
  237. #define DEV_BASIC_RATEMASK \
  238. ( DEV_RATEMASK_11MB | \
  239. DEV_RATEBIT_6MB | DEV_RATEBIT_12MB | DEV_RATEBIT_24MB )
  240. #define DEV_CCK_RATEMASK ( DEV_RATEMASK_11MB )
  241. #define DEV_OFDM_RATEMASK ( DEV_RATEMASK_54MB & ~DEV_CCK_RATEMASK )
  242. /*
  243. * Macro's to set and get specific fields from the device specific val and val2
  244. * fields inside the ieee80211_rate entry.
  245. */
  246. #define DEVICE_SET_RATE_FIELD(__value, __mask) \
  247. (int)( ((__value) << DEV_##__mask.bit_offset) & DEV_##__mask.bit_mask )
  248. #define DEVICE_GET_RATE_FIELD(__value, __mask) \
  249. (int)( ((__value) & DEV_##__mask.bit_mask) >> DEV_##__mask.bit_offset )
  250. #endif /* RT2X00REG_H */