ath.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef ATH_H
  17. #define ATH_H
  18. #include <linux/etherdevice.h>
  19. #include <linux/skbuff.h>
  20. #include <linux/if_ether.h>
  21. #include <linux/spinlock.h>
  22. #include <net/mac80211.h>
  23. /*
  24. * The key cache is used for h/w cipher state and also for
  25. * tracking station state such as the current tx antenna.
  26. * We also setup a mapping table between key cache slot indices
  27. * and station state to short-circuit node lookups on rx.
  28. * Different parts have different size key caches. We handle
  29. * up to ATH_KEYMAX entries (could dynamically allocate state).
  30. */
  31. #define ATH_KEYMAX 128 /* max key cache size we handle */
  32. static const u8 ath_bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  33. struct ath_ani {
  34. bool caldone;
  35. unsigned int longcal_timer;
  36. unsigned int shortcal_timer;
  37. unsigned int resetcal_timer;
  38. unsigned int checkani_timer;
  39. struct timer_list timer;
  40. };
  41. struct ath_cycle_counters {
  42. u32 cycles;
  43. u32 rx_busy;
  44. u32 rx_frame;
  45. u32 tx_frame;
  46. };
  47. enum ath_device_state {
  48. ATH_HW_UNAVAILABLE,
  49. ATH_HW_INITIALIZED,
  50. };
  51. enum ath_op_flags {
  52. ATH_OP_INVALID,
  53. ATH_OP_BEACONS,
  54. ATH_OP_ANI_RUN,
  55. ATH_OP_PRIM_STA_VIF,
  56. ATH_OP_HW_RESET,
  57. ATH_OP_SCANNING,
  58. };
  59. enum ath_bus_type {
  60. ATH_PCI,
  61. ATH_AHB,
  62. ATH_USB,
  63. };
  64. struct reg_dmn_pair_mapping {
  65. u16 reg_domain;
  66. u16 reg_5ghz_ctl;
  67. u16 reg_2ghz_ctl;
  68. };
  69. struct ath_regulatory {
  70. char alpha2[2];
  71. u16 country_code;
  72. u16 max_power_level;
  73. u16 current_rd;
  74. int16_t power_limit;
  75. struct reg_dmn_pair_mapping *regpair;
  76. };
  77. enum ath_crypt_caps {
  78. ATH_CRYPT_CAP_CIPHER_AESCCM = BIT(0),
  79. ATH_CRYPT_CAP_MIC_COMBINED = BIT(1),
  80. };
  81. struct ath_keyval {
  82. u8 kv_type;
  83. u8 kv_pad;
  84. u16 kv_len;
  85. u8 kv_val[16]; /* TK */
  86. u8 kv_mic[8]; /* Michael MIC key */
  87. u8 kv_txmic[8]; /* Michael MIC TX key (used only if the hardware
  88. * supports both MIC keys in the same key cache entry;
  89. * in that case, kv_mic is the RX key) */
  90. };
  91. enum ath_cipher {
  92. ATH_CIPHER_WEP = 0,
  93. ATH_CIPHER_AES_OCB = 1,
  94. ATH_CIPHER_AES_CCM = 2,
  95. ATH_CIPHER_CKIP = 3,
  96. ATH_CIPHER_TKIP = 4,
  97. ATH_CIPHER_CLR = 5,
  98. ATH_CIPHER_MIC = 127
  99. };
  100. /**
  101. * struct ath_ops - Register read/write operations
  102. *
  103. * @read: Register read
  104. * @multi_read: Multiple register read
  105. * @write: Register write
  106. * @enable_write_buffer: Enable multiple register writes
  107. * @write_flush: flush buffered register writes and disable buffering
  108. */
  109. struct ath_ops {
  110. unsigned int (*read)(void *, u32 reg_offset);
  111. void (*multi_read)(void *, u32 *addr, u32 *val, u16 count);
  112. void (*write)(void *, u32 val, u32 reg_offset);
  113. void (*enable_write_buffer)(void *);
  114. void (*write_flush) (void *);
  115. u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
  116. };
  117. struct ath_common;
  118. struct ath_bus_ops;
  119. struct ath_common {
  120. void *ah;
  121. void *priv;
  122. struct ieee80211_hw *hw;
  123. int debug_mask;
  124. enum ath_device_state state;
  125. unsigned long op_flags;
  126. struct ath_ani ani;
  127. u16 cachelsz;
  128. u16 curaid;
  129. u8 macaddr[ETH_ALEN];
  130. u8 curbssid[ETH_ALEN];
  131. u8 bssidmask[ETH_ALEN];
  132. u32 rx_bufsize;
  133. u32 keymax;
  134. DECLARE_BITMAP(keymap, ATH_KEYMAX);
  135. DECLARE_BITMAP(tkip_keymap, ATH_KEYMAX);
  136. DECLARE_BITMAP(ccmp_keymap, ATH_KEYMAX);
  137. enum ath_crypt_caps crypt_caps;
  138. unsigned int clockrate;
  139. spinlock_t cc_lock;
  140. struct ath_cycle_counters cc_ani;
  141. struct ath_cycle_counters cc_survey;
  142. struct ath_regulatory regulatory;
  143. struct ath_regulatory reg_world_copy;
  144. const struct ath_ops *ops;
  145. const struct ath_bus_ops *bus_ops;
  146. bool btcoex_enabled;
  147. bool disable_ani;
  148. bool bt_ant_diversity;
  149. int last_rssi;
  150. struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
  151. };
  152. struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
  153. u32 len,
  154. gfp_t gfp_mask);
  155. bool ath_is_mybeacon(struct ath_common *common, struct ieee80211_hdr *hdr);
  156. void ath_hw_setbssidmask(struct ath_common *common);
  157. void ath_key_delete(struct ath_common *common, struct ieee80211_key_conf *key);
  158. int ath_key_config(struct ath_common *common,
  159. struct ieee80211_vif *vif,
  160. struct ieee80211_sta *sta,
  161. struct ieee80211_key_conf *key);
  162. bool ath_hw_keyreset(struct ath_common *common, u16 entry);
  163. void ath_hw_cycle_counters_update(struct ath_common *common);
  164. int32_t ath_hw_get_listen_time(struct ath_common *common);
  165. __printf(3, 4)
  166. void ath_printk(const char *level, const struct ath_common *common,
  167. const char *fmt, ...);
  168. #define ath_emerg(common, fmt, ...) \
  169. ath_printk(KERN_EMERG, common, fmt, ##__VA_ARGS__)
  170. #define ath_alert(common, fmt, ...) \
  171. ath_printk(KERN_ALERT, common, fmt, ##__VA_ARGS__)
  172. #define ath_crit(common, fmt, ...) \
  173. ath_printk(KERN_CRIT, common, fmt, ##__VA_ARGS__)
  174. #define ath_err(common, fmt, ...) \
  175. ath_printk(KERN_ERR, common, fmt, ##__VA_ARGS__)
  176. #define ath_warn(common, fmt, ...) \
  177. ath_printk(KERN_WARNING, common, fmt, ##__VA_ARGS__)
  178. #define ath_notice(common, fmt, ...) \
  179. ath_printk(KERN_NOTICE, common, fmt, ##__VA_ARGS__)
  180. #define ath_info(common, fmt, ...) \
  181. ath_printk(KERN_INFO, common, fmt, ##__VA_ARGS__)
  182. /**
  183. * enum ath_debug_level - atheros wireless debug level
  184. *
  185. * @ATH_DBG_RESET: reset processing
  186. * @ATH_DBG_QUEUE: hardware queue management
  187. * @ATH_DBG_EEPROM: eeprom processing
  188. * @ATH_DBG_CALIBRATE: periodic calibration
  189. * @ATH_DBG_INTERRUPT: interrupt processing
  190. * @ATH_DBG_REGULATORY: regulatory processing
  191. * @ATH_DBG_ANI: adaptive noise immunitive processing
  192. * @ATH_DBG_XMIT: basic xmit operation
  193. * @ATH_DBG_BEACON: beacon handling
  194. * @ATH_DBG_CONFIG: configuration of the hardware
  195. * @ATH_DBG_FATAL: fatal errors, this is the default, DBG_DEFAULT
  196. * @ATH_DBG_PS: power save processing
  197. * @ATH_DBG_HWTIMER: hardware timer handling
  198. * @ATH_DBG_BTCOEX: bluetooth coexistance
  199. * @ATH_DBG_BSTUCK: stuck beacons
  200. * @ATH_DBG_MCI: Message Coexistence Interface, a private protocol
  201. * used exclusively for WLAN-BT coexistence starting from
  202. * AR9462.
  203. * @ATH_DBG_DFS: radar datection
  204. * @ATH_DBG_WOW: Wake on Wireless
  205. * @ATH_DBG_ANY: enable all debugging
  206. *
  207. * The debug level is used to control the amount and type of debugging output
  208. * we want to see. Each driver has its own method for enabling debugging and
  209. * modifying debug level states -- but this is typically done through a
  210. * module parameter 'debug' along with a respective 'debug' debugfs file
  211. * entry.
  212. */
  213. enum ATH_DEBUG {
  214. ATH_DBG_RESET = 0x00000001,
  215. ATH_DBG_QUEUE = 0x00000002,
  216. ATH_DBG_EEPROM = 0x00000004,
  217. ATH_DBG_CALIBRATE = 0x00000008,
  218. ATH_DBG_INTERRUPT = 0x00000010,
  219. ATH_DBG_REGULATORY = 0x00000020,
  220. ATH_DBG_ANI = 0x00000040,
  221. ATH_DBG_XMIT = 0x00000080,
  222. ATH_DBG_BEACON = 0x00000100,
  223. ATH_DBG_CONFIG = 0x00000200,
  224. ATH_DBG_FATAL = 0x00000400,
  225. ATH_DBG_PS = 0x00000800,
  226. ATH_DBG_BTCOEX = 0x00001000,
  227. ATH_DBG_WMI = 0x00002000,
  228. ATH_DBG_BSTUCK = 0x00004000,
  229. ATH_DBG_MCI = 0x00008000,
  230. ATH_DBG_DFS = 0x00010000,
  231. ATH_DBG_WOW = 0x00020000,
  232. ATH_DBG_ANY = 0xffffffff
  233. };
  234. #define ATH_DBG_DEFAULT (ATH_DBG_FATAL)
  235. #ifdef CONFIG_ATH_DEBUG
  236. #define ath_dbg(common, dbg_mask, fmt, ...) \
  237. do { \
  238. if ((common)->debug_mask & ATH_DBG_##dbg_mask) \
  239. ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__); \
  240. } while (0)
  241. #define ATH_DBG_WARN(foo, arg...) WARN(foo, arg)
  242. #define ATH_DBG_WARN_ON_ONCE(foo) WARN_ON_ONCE(foo)
  243. #else
  244. static inline __attribute__ ((format (printf, 3, 4)))
  245. void _ath_dbg(struct ath_common *common, enum ATH_DEBUG dbg_mask,
  246. const char *fmt, ...)
  247. {
  248. }
  249. #define ath_dbg(common, dbg_mask, fmt, ...) \
  250. _ath_dbg(common, ATH_DBG_##dbg_mask, fmt, ##__VA_ARGS__)
  251. #define ATH_DBG_WARN(foo, arg...) do {} while (0)
  252. #define ATH_DBG_WARN_ON_ONCE(foo) ({ \
  253. int __ret_warn_once = !!(foo); \
  254. unlikely(__ret_warn_once); \
  255. })
  256. #endif /* CONFIG_ATH_DEBUG */
  257. /** Returns string describing opmode, or NULL if unknown mode. */
  258. #ifdef CONFIG_ATH_DEBUG
  259. const char *ath_opmode_to_string(enum nl80211_iftype opmode);
  260. #else
  261. static inline const char *ath_opmode_to_string(enum nl80211_iftype opmode)
  262. {
  263. return "UNKNOWN";
  264. }
  265. #endif
  266. #endif /* ATH_H */