rt2x00reg.h 7.1 KB

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