rt2x00lib.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. Copyright (C) 2004 - 2009 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: rt2x00lib
  19. Abstract: Data structures and definitions for the rt2x00lib module.
  20. */
  21. #ifndef RT2X00LIB_H
  22. #define RT2X00LIB_H
  23. #include "rt2x00dump.h"
  24. /*
  25. * Interval defines
  26. * Both the link tuner as the rfkill will be called once per second.
  27. */
  28. #define LINK_TUNE_INTERVAL ( round_jiffies_relative(HZ) )
  29. #define RFKILL_POLL_INTERVAL ( 1000 )
  30. /*
  31. * rt2x00_rate: Per rate device information
  32. */
  33. struct rt2x00_rate {
  34. unsigned short flags;
  35. #define DEV_RATE_CCK 0x0001
  36. #define DEV_RATE_OFDM 0x0002
  37. #define DEV_RATE_SHORT_PREAMBLE 0x0004
  38. unsigned short bitrate; /* In 100kbit/s */
  39. unsigned short ratemask;
  40. unsigned short plcp;
  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. /*
  48. * Radio control handlers.
  49. */
  50. int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev);
  51. void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev);
  52. void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state);
  53. /*
  54. * Initialization handlers.
  55. */
  56. int rt2x00lib_start(struct rt2x00_dev *rt2x00dev);
  57. void rt2x00lib_stop(struct rt2x00_dev *rt2x00dev);
  58. /*
  59. * Configuration handlers.
  60. */
  61. void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
  62. struct rt2x00_intf *intf,
  63. enum nl80211_iftype type,
  64. const u8 *mac, const u8 *bssid);
  65. void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
  66. struct rt2x00_intf *intf,
  67. struct ieee80211_bss_conf *conf);
  68. void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
  69. struct antenna_setup *ant);
  70. void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
  71. struct ieee80211_conf *conf,
  72. const unsigned int changed_flags);
  73. /**
  74. * DOC: Queue handlers
  75. */
  76. /**
  77. * rt2x00queue_alloc_rxskb - allocate a skb for RX purposes.
  78. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  79. * @queue: The queue for which the skb will be applicable.
  80. */
  81. struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev,
  82. struct queue_entry *entry);
  83. /**
  84. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  85. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  86. * @skb: The skb to unmap.
  87. */
  88. void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  89. /**
  90. * rt2x00queue_free_skb - free a skb
  91. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  92. * @skb: The skb to free.
  93. */
  94. void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  95. /**
  96. * rt2x00queue_write_tx_frame - Write TX frame to hardware
  97. * @queue: Queue over which the frame should be send
  98. * @skb: The skb to send
  99. */
  100. int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb);
  101. /**
  102. * rt2x00queue_update_beacon - Send new beacon from mac80211 to hardware
  103. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  104. * @vif: Interface for which the beacon should be updated.
  105. * @enable_beacon: Enable beaconing
  106. */
  107. int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
  108. struct ieee80211_vif *vif,
  109. const bool enable_beacon);
  110. /**
  111. * rt2x00queue_index_inc - Index incrementation function
  112. * @queue: Queue (&struct data_queue) to perform the action on.
  113. * @index: Index type (&enum queue_index) to perform the action on.
  114. *
  115. * This function will increase the requested index on the queue,
  116. * it will grab the appropriate locks and handle queue overflow events by
  117. * resetting the index to the start of the queue.
  118. */
  119. void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
  120. /**
  121. * rt2x00queue_stop_queues - Halt all data queues
  122. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  123. *
  124. * This function will loop through all available queues to stop
  125. * any pending outgoing frames.
  126. */
  127. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  128. /**
  129. * rt2x00queue_init_queues - Initialize all data queues
  130. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  131. *
  132. * This function will loop through all available queues to clear all
  133. * index numbers and set the queue entry to the correct initialization
  134. * state.
  135. */
  136. void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev);
  137. int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev);
  138. void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev);
  139. int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev);
  140. void rt2x00queue_free(struct rt2x00_dev *rt2x00dev);
  141. /**
  142. * rt2x00link_update_stats - Update link statistics from RX frame
  143. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  144. * @skb: Received frame
  145. * @rxdesc: Received frame descriptor
  146. *
  147. * Update link statistics based on the information from the
  148. * received frame descriptor.
  149. */
  150. void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev,
  151. struct sk_buff *skb,
  152. struct rxdone_entry_desc *rxdesc);
  153. /**
  154. * rt2x00link_calculate_signal - Calculate signal quality
  155. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  156. * @rssi: RX Frame RSSI
  157. *
  158. * Calculate the signal quality of a frame based on the rssi
  159. * measured during the receiving of the frame and the global
  160. * link quality statistics measured since the start of the
  161. * link tuning. The result is a value between 0 and 100 which
  162. * is an indication of the signal quality.
  163. */
  164. int rt2x00link_calculate_signal(struct rt2x00_dev *rt2x00dev, int rssi);
  165. /**
  166. * rt2x00link_start_tuner - Start periodic link tuner work
  167. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  168. *
  169. * This start the link tuner periodic work, this work will
  170. * be executed periodically until &rt2x00link_stop_tuner has
  171. * been called.
  172. */
  173. void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev);
  174. /**
  175. * rt2x00link_stop_tuner - Stop periodic link tuner work
  176. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  177. *
  178. * After this function completed the link tuner will not
  179. * be running until &rt2x00link_start_tuner is called.
  180. */
  181. void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev);
  182. /**
  183. * rt2x00link_reset_tuner - Reset periodic link tuner work
  184. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  185. * @antenna: Should the antenna tuning also be reset
  186. *
  187. * The VGC limit configured in the hardware will be reset to 0
  188. * which forces the driver to rediscover the correct value for
  189. * the current association. This is needed when configuration
  190. * options have changed which could drastically change the
  191. * SNR level or link quality (i.e. changing the antenna setting).
  192. *
  193. * Resetting the link tuner will also cause the periodic work counter
  194. * to be reset. Any driver which has a fixed limit on the number
  195. * of rounds the link tuner is supposed to work will accept the
  196. * tuner actions again if this limit was previously reached.
  197. *
  198. * If @antenna is set to true a the software antenna diversity
  199. * tuning will also be reset.
  200. */
  201. void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna);
  202. /**
  203. * rt2x00link_register - Initialize link tuning functionality
  204. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  205. *
  206. * Initialize work structure and all link tuning related
  207. * paramters. This will not start the link tuning process itself.
  208. */
  209. void rt2x00link_register(struct rt2x00_dev *rt2x00dev);
  210. /*
  211. * Firmware handlers.
  212. */
  213. #ifdef CONFIG_RT2X00_LIB_FIRMWARE
  214. int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev);
  215. void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev);
  216. #else
  217. static inline int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
  218. {
  219. return 0;
  220. }
  221. static inline void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
  222. {
  223. }
  224. #endif /* CONFIG_RT2X00_LIB_FIRMWARE */
  225. /*
  226. * Debugfs handlers.
  227. */
  228. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  229. void rt2x00debug_register(struct rt2x00_dev *rt2x00dev);
  230. void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev);
  231. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  232. enum rt2x00_dump_type type, struct sk_buff *skb);
  233. void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  234. struct rxdone_entry_desc *rxdesc);
  235. #else
  236. static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
  237. {
  238. }
  239. static inline void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
  240. {
  241. }
  242. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  243. enum rt2x00_dump_type type,
  244. struct sk_buff *skb)
  245. {
  246. }
  247. static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  248. struct rxdone_entry_desc *rxdesc)
  249. {
  250. }
  251. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  252. /*
  253. * Crypto handlers.
  254. */
  255. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  256. enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key);
  257. void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
  258. struct txentry_desc *txdesc);
  259. unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  260. struct sk_buff *skb);
  261. void rt2x00crypto_tx_copy_iv(struct sk_buff *skb, unsigned int iv_len);
  262. void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len);
  263. void rt2x00crypto_tx_insert_iv(struct sk_buff *skb);
  264. void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
  265. unsigned int header_length,
  266. struct rxdone_entry_desc *rxdesc);
  267. #else
  268. static inline enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
  269. {
  270. return CIPHER_NONE;
  271. }
  272. static inline void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
  273. struct txentry_desc *txdesc)
  274. {
  275. }
  276. static inline unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  277. struct sk_buff *skb)
  278. {
  279. return 0;
  280. }
  281. static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
  282. unsigned int iv_len)
  283. {
  284. }
  285. static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
  286. unsigned int iv_len)
  287. {
  288. }
  289. static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
  290. {
  291. }
  292. static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
  293. unsigned int align,
  294. unsigned int header_length,
  295. struct rxdone_entry_desc *rxdesc)
  296. {
  297. }
  298. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  299. /*
  300. * RFkill handlers.
  301. */
  302. #ifdef CONFIG_RT2X00_LIB_RFKILL
  303. void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev);
  304. void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev);
  305. void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev);
  306. void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev);
  307. #else
  308. static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
  309. {
  310. }
  311. static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
  312. {
  313. }
  314. static inline void rt2x00rfkill_allocate(struct rt2x00_dev *rt2x00dev)
  315. {
  316. }
  317. static inline void rt2x00rfkill_free(struct rt2x00_dev *rt2x00dev)
  318. {
  319. }
  320. #endif /* CONFIG_RT2X00_LIB_RFKILL */
  321. /*
  322. * LED handlers
  323. */
  324. #ifdef CONFIG_RT2X00_LIB_LEDS
  325. void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi);
  326. void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled);
  327. void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled);
  328. void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled);
  329. void rt2x00leds_register(struct rt2x00_dev *rt2x00dev);
  330. void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev);
  331. void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev);
  332. void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev);
  333. #else
  334. static inline void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev,
  335. int rssi)
  336. {
  337. }
  338. static inline void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev,
  339. bool enabled)
  340. {
  341. }
  342. static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev,
  343. bool enabled)
  344. {
  345. }
  346. static inline void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev,
  347. bool enabled)
  348. {
  349. }
  350. static inline void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
  351. {
  352. }
  353. static inline void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
  354. {
  355. }
  356. static inline void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev)
  357. {
  358. }
  359. static inline void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev)
  360. {
  361. }
  362. #endif /* CONFIG_RT2X00_LIB_LEDS */
  363. #endif /* RT2X00LIB_H */