rt2x00lib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*
  2. Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
  3. Copyright (C) 2004 - 2009 Gertjan van Wingerde <gwingerde@gmail.com>
  4. <http://rt2x00.serialmonkey.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. Module: rt2x00lib
  18. Abstract: Data structures and definitions for the rt2x00lib module.
  19. */
  20. #ifndef RT2X00LIB_H
  21. #define RT2X00LIB_H
  22. /*
  23. * Interval defines
  24. */
  25. #define WATCHDOG_INTERVAL round_jiffies_relative(HZ)
  26. #define LINK_TUNE_INTERVAL round_jiffies_relative(HZ)
  27. #define AGC_INTERVAL round_jiffies_relative(4 * HZ)
  28. #define VCO_INTERVAL round_jiffies_relative(10 * HZ) /* 10 sec */
  29. /*
  30. * rt2x00_rate: Per rate device information
  31. */
  32. struct rt2x00_rate {
  33. unsigned short flags;
  34. #define DEV_RATE_CCK 0x0001
  35. #define DEV_RATE_OFDM 0x0002
  36. #define DEV_RATE_SHORT_PREAMBLE 0x0004
  37. unsigned short bitrate; /* In 100kbit/s */
  38. unsigned short ratemask;
  39. unsigned short plcp;
  40. unsigned short mcs;
  41. };
  42. extern const struct rt2x00_rate rt2x00_supported_rates[12];
  43. static inline const struct rt2x00_rate *rt2x00_get_rate(const u16 hw_value)
  44. {
  45. return &rt2x00_supported_rates[hw_value & 0xff];
  46. }
  47. #define RATE_MCS(__mode, __mcs) \
  48. ((((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff))
  49. static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
  50. {
  51. return (mcs_value & 0x00ff);
  52. }
  53. /*
  54. * Radio control handlers.
  55. */
  56. int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev);
  57. void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev);
  58. /*
  59. * Initialization handlers.
  60. */
  61. int rt2x00lib_start(struct rt2x00_dev *rt2x00dev);
  62. void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev);
  63. /*
  64. * Configuration handlers.
  65. */
  66. void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
  67. struct rt2x00_intf *intf,
  68. enum nl80211_iftype type,
  69. const u8 *mac, const u8 *bssid);
  70. void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
  71. struct rt2x00_intf *intf,
  72. struct ieee80211_bss_conf *conf,
  73. u32 changed);
  74. void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
  75. struct antenna_setup ant);
  76. void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
  77. struct ieee80211_conf *conf,
  78. const unsigned int changed_flags);
  79. /**
  80. * DOC: Queue handlers
  81. */
  82. /**
  83. * rt2x00queue_alloc_rxskb - allocate a skb for RX purposes.
  84. * @entry: The entry for which the skb will be applicable.
  85. */
  86. struct sk_buff *rt2x00queue_alloc_rxskb(struct queue_entry *entry, gfp_t gfp);
  87. /**
  88. * rt2x00queue_free_skb - free a skb
  89. * @entry: The entry for which the skb will be applicable.
  90. */
  91. void rt2x00queue_free_skb(struct queue_entry *entry);
  92. /**
  93. * rt2x00queue_align_frame - Align 802.11 frame to 4-byte boundary
  94. * @skb: The skb to align
  95. *
  96. * Align the start of the 802.11 frame to a 4-byte boundary, this could
  97. * mean the payload is not aligned properly though.
  98. */
  99. void rt2x00queue_align_frame(struct sk_buff *skb);
  100. /**
  101. * rt2x00queue_insert_l2pad - Align 802.11 header & payload to 4-byte boundary
  102. * @skb: The skb to align
  103. * @header_length: Length of 802.11 header
  104. *
  105. * Apply L2 padding to align both header and payload to 4-byte boundary
  106. */
  107. void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length);
  108. /**
  109. * rt2x00queue_insert_l2pad - Remove L2 padding from 802.11 frame
  110. * @skb: The skb to align
  111. * @header_length: Length of 802.11 header
  112. *
  113. * Remove L2 padding used to align both header and payload to 4-byte boundary,
  114. * by removing the L2 padding the header will no longer be 4-byte aligned.
  115. */
  116. void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length);
  117. /**
  118. * rt2x00queue_write_tx_frame - Write TX frame to hardware
  119. * @queue: Queue over which the frame should be send
  120. * @skb: The skb to send
  121. * @local: frame is not from mac80211
  122. */
  123. int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
  124. struct ieee80211_sta *sta, bool local);
  125. /**
  126. * rt2x00queue_update_beacon - Send new beacon from mac80211
  127. * to hardware. Handles locking by itself (mutex).
  128. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  129. * @vif: Interface for which the beacon should be updated.
  130. */
  131. int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
  132. struct ieee80211_vif *vif);
  133. /**
  134. * rt2x00queue_update_beacon_locked - Send new beacon from mac80211
  135. * to hardware. Caller needs to ensure locking.
  136. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  137. * @vif: Interface for which the beacon should be updated.
  138. */
  139. int rt2x00queue_update_beacon_locked(struct rt2x00_dev *rt2x00dev,
  140. struct ieee80211_vif *vif);
  141. /**
  142. * rt2x00queue_clear_beacon - Clear beacon in hardware
  143. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  144. * @vif: Interface for which the beacon should be updated.
  145. */
  146. int rt2x00queue_clear_beacon(struct rt2x00_dev *rt2x00dev,
  147. struct ieee80211_vif *vif);
  148. /**
  149. * rt2x00queue_index_inc - Index incrementation function
  150. * @entry: Queue entry (&struct queue_entry) to perform the action on.
  151. * @index: Index type (&enum queue_index) to perform the action on.
  152. *
  153. * This function will increase the requested index on the entry's queue,
  154. * it will grab the appropriate locks and handle queue overflow events by
  155. * resetting the index to the start of the queue.
  156. */
  157. void rt2x00queue_index_inc(struct queue_entry *entry, enum queue_index index);
  158. /**
  159. * rt2x00queue_init_queues - Initialize all data queues
  160. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  161. *
  162. * This function will loop through all available queues to clear all
  163. * index numbers and set the queue entry to the correct initialization
  164. * state.
  165. */
  166. void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev);
  167. int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev);
  168. void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev);
  169. int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev);
  170. void rt2x00queue_free(struct rt2x00_dev *rt2x00dev);
  171. /**
  172. * rt2x00link_update_stats - Update link statistics from RX frame
  173. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  174. * @skb: Received frame
  175. * @rxdesc: Received frame descriptor
  176. *
  177. * Update link statistics based on the information from the
  178. * received frame descriptor.
  179. */
  180. void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev,
  181. struct sk_buff *skb,
  182. struct rxdone_entry_desc *rxdesc);
  183. /**
  184. * rt2x00link_start_tuner - Start periodic link tuner work
  185. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  186. *
  187. * This start the link tuner periodic work, this work will
  188. * be executed periodically until &rt2x00link_stop_tuner has
  189. * been called.
  190. */
  191. void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev);
  192. /**
  193. * rt2x00link_stop_tuner - Stop periodic link tuner work
  194. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  195. *
  196. * After this function completed the link tuner will not
  197. * be running until &rt2x00link_start_tuner is called.
  198. */
  199. void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev);
  200. /**
  201. * rt2x00link_reset_tuner - Reset periodic link tuner work
  202. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  203. * @antenna: Should the antenna tuning also be reset
  204. *
  205. * The VGC limit configured in the hardware will be reset to 0
  206. * which forces the driver to rediscover the correct value for
  207. * the current association. This is needed when configuration
  208. * options have changed which could drastically change the
  209. * SNR level or link quality (i.e. changing the antenna setting).
  210. *
  211. * Resetting the link tuner will also cause the periodic work counter
  212. * to be reset. Any driver which has a fixed limit on the number
  213. * of rounds the link tuner is supposed to work will accept the
  214. * tuner actions again if this limit was previously reached.
  215. *
  216. * If @antenna is set to true a the software antenna diversity
  217. * tuning will also be reset.
  218. */
  219. void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna);
  220. /**
  221. * rt2x00link_start_watchdog - Start periodic watchdog monitoring
  222. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  223. *
  224. * This start the watchdog periodic work, this work will
  225. *be executed periodically until &rt2x00link_stop_watchdog has
  226. * been called.
  227. */
  228. void rt2x00link_start_watchdog(struct rt2x00_dev *rt2x00dev);
  229. /**
  230. * rt2x00link_stop_watchdog - Stop periodic watchdog monitoring
  231. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  232. *
  233. * After this function completed the watchdog monitoring will not
  234. * be running until &rt2x00link_start_watchdog is called.
  235. */
  236. void rt2x00link_stop_watchdog(struct rt2x00_dev *rt2x00dev);
  237. /**
  238. * rt2x00link_start_agc - Start periodic gain calibration
  239. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  240. */
  241. void rt2x00link_start_agc(struct rt2x00_dev *rt2x00dev);
  242. /**
  243. * rt2x00link_start_vcocal - Start periodic VCO calibration
  244. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  245. */
  246. void rt2x00link_start_vcocal(struct rt2x00_dev *rt2x00dev);
  247. /**
  248. * rt2x00link_stop_agc - Stop periodic gain calibration
  249. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  250. */
  251. void rt2x00link_stop_agc(struct rt2x00_dev *rt2x00dev);
  252. /**
  253. * rt2x00link_stop_vcocal - Stop periodic VCO calibration
  254. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  255. */
  256. void rt2x00link_stop_vcocal(struct rt2x00_dev *rt2x00dev);
  257. /**
  258. * rt2x00link_register - Initialize link tuning & watchdog functionality
  259. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  260. *
  261. * Initialize work structure and all link tuning and watchdog related
  262. * parameters. This will not start the periodic work itself.
  263. */
  264. void rt2x00link_register(struct rt2x00_dev *rt2x00dev);
  265. /*
  266. * Firmware handlers.
  267. */
  268. #ifdef CONFIG_RT2X00_LIB_FIRMWARE
  269. int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev);
  270. void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev);
  271. #else
  272. static inline int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
  273. {
  274. return 0;
  275. }
  276. static inline void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
  277. {
  278. }
  279. #endif /* CONFIG_RT2X00_LIB_FIRMWARE */
  280. /*
  281. * Debugfs handlers.
  282. */
  283. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  284. void rt2x00debug_register(struct rt2x00_dev *rt2x00dev);
  285. void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev);
  286. void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  287. struct rxdone_entry_desc *rxdesc);
  288. #else
  289. static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
  290. {
  291. }
  292. static inline void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
  293. {
  294. }
  295. static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  296. struct rxdone_entry_desc *rxdesc)
  297. {
  298. }
  299. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  300. /*
  301. * Crypto handlers.
  302. */
  303. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  304. enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key);
  305. void rt2x00crypto_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
  306. struct sk_buff *skb,
  307. struct txentry_desc *txdesc);
  308. unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  309. struct sk_buff *skb);
  310. void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
  311. struct txentry_desc *txdesc);
  312. void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
  313. struct txentry_desc *txdesc);
  314. void rt2x00crypto_tx_insert_iv(struct sk_buff *skb, unsigned int header_length);
  315. void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
  316. unsigned int header_length,
  317. struct rxdone_entry_desc *rxdesc);
  318. #else
  319. static inline enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
  320. {
  321. return CIPHER_NONE;
  322. }
  323. static inline void rt2x00crypto_create_tx_descriptor(struct rt2x00_dev *rt2x00dev,
  324. struct sk_buff *skb,
  325. struct txentry_desc *txdesc)
  326. {
  327. }
  328. static inline unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  329. struct sk_buff *skb)
  330. {
  331. return 0;
  332. }
  333. static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
  334. struct txentry_desc *txdesc)
  335. {
  336. }
  337. static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
  338. struct txentry_desc *txdesc)
  339. {
  340. }
  341. static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb,
  342. unsigned int header_length)
  343. {
  344. }
  345. static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
  346. unsigned int header_length,
  347. struct rxdone_entry_desc *rxdesc)
  348. {
  349. }
  350. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  351. /*
  352. * RFkill handlers.
  353. */
  354. static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
  355. {
  356. if (test_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags))
  357. wiphy_rfkill_start_polling(rt2x00dev->hw->wiphy);
  358. }
  359. static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
  360. {
  361. if (test_bit(CAPABILITY_HW_BUTTON, &rt2x00dev->cap_flags))
  362. wiphy_rfkill_stop_polling(rt2x00dev->hw->wiphy);
  363. }
  364. /*
  365. * LED handlers
  366. */
  367. #ifdef CONFIG_RT2X00_LIB_LEDS
  368. void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi);
  369. void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled);
  370. void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled);
  371. void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled);
  372. void rt2x00leds_register(struct rt2x00_dev *rt2x00dev);
  373. void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev);
  374. void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev);
  375. void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev);
  376. #else
  377. static inline void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev,
  378. int rssi)
  379. {
  380. }
  381. static inline void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev,
  382. bool enabled)
  383. {
  384. }
  385. static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev,
  386. bool enabled)
  387. {
  388. }
  389. static inline void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev,
  390. bool enabled)
  391. {
  392. }
  393. static inline void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
  394. {
  395. }
  396. static inline void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
  397. {
  398. }
  399. static inline void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev)
  400. {
  401. }
  402. static inline void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev)
  403. {
  404. }
  405. #endif /* CONFIG_RT2X00_LIB_LEDS */
  406. #endif /* RT2X00LIB_H */