rt2x00lib.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. */
  27. #define LINK_TUNE_INTERVAL round_jiffies_relative(HZ)
  28. /*
  29. * rt2x00_rate: Per rate device information
  30. */
  31. struct rt2x00_rate {
  32. unsigned short flags;
  33. #define DEV_RATE_CCK 0x0001
  34. #define DEV_RATE_OFDM 0x0002
  35. #define DEV_RATE_SHORT_PREAMBLE 0x0004
  36. unsigned short bitrate; /* In 100kbit/s */
  37. unsigned short ratemask;
  38. unsigned short plcp;
  39. unsigned short mcs;
  40. };
  41. extern const struct rt2x00_rate rt2x00_supported_rates[12];
  42. static inline const struct rt2x00_rate *rt2x00_get_rate(const u16 hw_value)
  43. {
  44. return &rt2x00_supported_rates[hw_value & 0xff];
  45. }
  46. #define RATE_MCS(__mode, __mcs) \
  47. ( (((__mode) & 0x00ff) << 8) | ((__mcs) & 0x00ff) )
  48. static inline int rt2x00_get_rate_mcs(const u16 mcs_value)
  49. {
  50. return (mcs_value & 0x00ff);
  51. }
  52. /*
  53. * Radio control handlers.
  54. */
  55. int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev);
  56. void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev);
  57. void rt2x00lib_toggle_rx(struct rt2x00_dev *rt2x00dev, enum dev_state state);
  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. void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
  74. struct antenna_setup ant);
  75. void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
  76. struct ieee80211_conf *conf,
  77. const unsigned int changed_flags);
  78. /**
  79. * DOC: Queue handlers
  80. */
  81. /**
  82. * rt2x00queue_alloc_rxskb - allocate a skb for RX purposes.
  83. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  84. * @queue: The queue for which the skb will be applicable.
  85. */
  86. struct sk_buff *rt2x00queue_alloc_rxskb(struct rt2x00_dev *rt2x00dev,
  87. struct queue_entry *entry);
  88. /**
  89. * rt2x00queue_unmap_skb - Unmap a skb from DMA.
  90. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  91. * @skb: The skb to unmap.
  92. */
  93. void rt2x00queue_unmap_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  94. /**
  95. * rt2x00queue_free_skb - free a skb
  96. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  97. * @skb: The skb to free.
  98. */
  99. void rt2x00queue_free_skb(struct rt2x00_dev *rt2x00dev, struct sk_buff *skb);
  100. /**
  101. * rt2x00queue_align_frame - Align 802.11 frame to 4-byte boundary
  102. * @skb: The skb to align
  103. *
  104. * Align the start of the 802.11 frame to a 4-byte boundary, this could
  105. * mean the payload is not aligned properly though.
  106. */
  107. void rt2x00queue_align_frame(struct sk_buff *skb);
  108. /**
  109. * rt2x00queue_align_payload - Align 802.11 payload to 4-byte boundary
  110. * @skb: The skb to align
  111. * @header_length: Length of 802.11 header
  112. *
  113. * Align the 802.11 payload to a 4-byte boundary, this could
  114. * mean the header is not aligned properly though.
  115. */
  116. void rt2x00queue_align_payload(struct sk_buff *skb, unsigned int header_length);
  117. /**
  118. * rt2x00queue_insert_l2pad - Align 802.11 header & payload to 4-byte boundary
  119. * @skb: The skb to align
  120. * @header_length: Length of 802.11 header
  121. *
  122. * Apply L2 padding to align both header and payload to 4-byte boundary
  123. */
  124. void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length);
  125. /**
  126. * rt2x00queue_insert_l2pad - Remove L2 padding from 802.11 frame
  127. * @skb: The skb to align
  128. * @header_length: Length of 802.11 header
  129. *
  130. * Remove L2 padding used to align both header and payload to 4-byte boundary,
  131. * by removing the L2 padding the header will no longer be 4-byte aligned.
  132. */
  133. void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length);
  134. /**
  135. * rt2x00queue_write_tx_frame - Write TX frame to hardware
  136. * @queue: Queue over which the frame should be send
  137. * @skb: The skb to send
  138. */
  139. int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb);
  140. /**
  141. * rt2x00queue_update_beacon - Send new beacon from mac80211 to hardware
  142. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  143. * @vif: Interface for which the beacon should be updated.
  144. * @enable_beacon: Enable beaconing
  145. */
  146. int rt2x00queue_update_beacon(struct rt2x00_dev *rt2x00dev,
  147. struct ieee80211_vif *vif,
  148. const bool enable_beacon);
  149. /**
  150. * rt2x00queue_index_inc - Index incrementation function
  151. * @queue: Queue (&struct data_queue) to perform the action on.
  152. * @index: Index type (&enum queue_index) to perform the action on.
  153. *
  154. * This function will increase the requested index on the queue,
  155. * it will grab the appropriate locks and handle queue overflow events by
  156. * resetting the index to the start of the queue.
  157. */
  158. void rt2x00queue_index_inc(struct data_queue *queue, enum queue_index index);
  159. /**
  160. * rt2x00queue_stop_queues - Halt all data queues
  161. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  162. *
  163. * This function will loop through all available queues to stop
  164. * any pending outgoing frames.
  165. */
  166. void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
  167. /**
  168. * rt2x00queue_init_queues - Initialize all data queues
  169. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  170. *
  171. * This function will loop through all available queues to clear all
  172. * index numbers and set the queue entry to the correct initialization
  173. * state.
  174. */
  175. void rt2x00queue_init_queues(struct rt2x00_dev *rt2x00dev);
  176. int rt2x00queue_initialize(struct rt2x00_dev *rt2x00dev);
  177. void rt2x00queue_uninitialize(struct rt2x00_dev *rt2x00dev);
  178. int rt2x00queue_allocate(struct rt2x00_dev *rt2x00dev);
  179. void rt2x00queue_free(struct rt2x00_dev *rt2x00dev);
  180. /**
  181. * rt2x00link_update_stats - Update link statistics from RX frame
  182. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  183. * @skb: Received frame
  184. * @rxdesc: Received frame descriptor
  185. *
  186. * Update link statistics based on the information from the
  187. * received frame descriptor.
  188. */
  189. void rt2x00link_update_stats(struct rt2x00_dev *rt2x00dev,
  190. struct sk_buff *skb,
  191. struct rxdone_entry_desc *rxdesc);
  192. /**
  193. * rt2x00link_calculate_signal - Calculate signal quality
  194. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  195. * @rssi: RX Frame RSSI
  196. *
  197. * Calculate the signal quality of a frame based on the rssi
  198. * measured during the receiving of the frame and the global
  199. * link quality statistics measured since the start of the
  200. * link tuning. The result is a value between 0 and 100 which
  201. * is an indication of the signal quality.
  202. */
  203. int rt2x00link_calculate_signal(struct rt2x00_dev *rt2x00dev, int rssi);
  204. /**
  205. * rt2x00link_start_tuner - Start periodic link tuner work
  206. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  207. *
  208. * This start the link tuner periodic work, this work will
  209. * be executed periodically until &rt2x00link_stop_tuner has
  210. * been called.
  211. */
  212. void rt2x00link_start_tuner(struct rt2x00_dev *rt2x00dev);
  213. /**
  214. * rt2x00link_stop_tuner - Stop periodic link tuner work
  215. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  216. *
  217. * After this function completed the link tuner will not
  218. * be running until &rt2x00link_start_tuner is called.
  219. */
  220. void rt2x00link_stop_tuner(struct rt2x00_dev *rt2x00dev);
  221. /**
  222. * rt2x00link_reset_tuner - Reset periodic link tuner work
  223. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  224. * @antenna: Should the antenna tuning also be reset
  225. *
  226. * The VGC limit configured in the hardware will be reset to 0
  227. * which forces the driver to rediscover the correct value for
  228. * the current association. This is needed when configuration
  229. * options have changed which could drastically change the
  230. * SNR level or link quality (i.e. changing the antenna setting).
  231. *
  232. * Resetting the link tuner will also cause the periodic work counter
  233. * to be reset. Any driver which has a fixed limit on the number
  234. * of rounds the link tuner is supposed to work will accept the
  235. * tuner actions again if this limit was previously reached.
  236. *
  237. * If @antenna is set to true a the software antenna diversity
  238. * tuning will also be reset.
  239. */
  240. void rt2x00link_reset_tuner(struct rt2x00_dev *rt2x00dev, bool antenna);
  241. /**
  242. * rt2x00link_register - Initialize link tuning functionality
  243. * @rt2x00dev: Pointer to &struct rt2x00_dev.
  244. *
  245. * Initialize work structure and all link tuning related
  246. * parameters. This will not start the link tuning process itself.
  247. */
  248. void rt2x00link_register(struct rt2x00_dev *rt2x00dev);
  249. /*
  250. * Firmware handlers.
  251. */
  252. #ifdef CONFIG_RT2X00_LIB_FIRMWARE
  253. int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev);
  254. void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev);
  255. #else
  256. static inline int rt2x00lib_load_firmware(struct rt2x00_dev *rt2x00dev)
  257. {
  258. return 0;
  259. }
  260. static inline void rt2x00lib_free_firmware(struct rt2x00_dev *rt2x00dev)
  261. {
  262. }
  263. #endif /* CONFIG_RT2X00_LIB_FIRMWARE */
  264. /*
  265. * Debugfs handlers.
  266. */
  267. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  268. void rt2x00debug_register(struct rt2x00_dev *rt2x00dev);
  269. void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev);
  270. void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  271. enum rt2x00_dump_type type, struct sk_buff *skb);
  272. void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  273. struct rxdone_entry_desc *rxdesc);
  274. #else
  275. static inline void rt2x00debug_register(struct rt2x00_dev *rt2x00dev)
  276. {
  277. }
  278. static inline void rt2x00debug_deregister(struct rt2x00_dev *rt2x00dev)
  279. {
  280. }
  281. static inline void rt2x00debug_dump_frame(struct rt2x00_dev *rt2x00dev,
  282. enum rt2x00_dump_type type,
  283. struct sk_buff *skb)
  284. {
  285. }
  286. static inline void rt2x00debug_update_crypto(struct rt2x00_dev *rt2x00dev,
  287. struct rxdone_entry_desc *rxdesc)
  288. {
  289. }
  290. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  291. /*
  292. * Crypto handlers.
  293. */
  294. #ifdef CONFIG_RT2X00_LIB_CRYPTO
  295. enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key);
  296. void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
  297. struct txentry_desc *txdesc);
  298. unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  299. struct sk_buff *skb);
  300. void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
  301. struct txentry_desc *txdesc);
  302. void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
  303. struct txentry_desc *txdesc);
  304. void rt2x00crypto_tx_insert_iv(struct sk_buff *skb, unsigned int header_length);
  305. void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
  306. unsigned int header_length,
  307. struct rxdone_entry_desc *rxdesc);
  308. #else
  309. static inline enum cipher rt2x00crypto_key_to_cipher(struct ieee80211_key_conf *key)
  310. {
  311. return CIPHER_NONE;
  312. }
  313. static inline void rt2x00crypto_create_tx_descriptor(struct queue_entry *entry,
  314. struct txentry_desc *txdesc)
  315. {
  316. }
  317. static inline unsigned int rt2x00crypto_tx_overhead(struct rt2x00_dev *rt2x00dev,
  318. struct sk_buff *skb)
  319. {
  320. return 0;
  321. }
  322. static inline void rt2x00crypto_tx_copy_iv(struct sk_buff *skb,
  323. struct txentry_desc *txdesc)
  324. {
  325. }
  326. static inline void rt2x00crypto_tx_remove_iv(struct sk_buff *skb,
  327. struct txentry_desc *txdesc)
  328. {
  329. }
  330. static inline void rt2x00crypto_tx_insert_iv(struct sk_buff *skb,
  331. unsigned int header_length)
  332. {
  333. }
  334. static inline void rt2x00crypto_rx_insert_iv(struct sk_buff *skb,
  335. unsigned int header_length,
  336. struct rxdone_entry_desc *rxdesc)
  337. {
  338. }
  339. #endif /* CONFIG_RT2X00_LIB_CRYPTO */
  340. /*
  341. * HT handlers.
  342. */
  343. #ifdef CONFIG_RT2X00_LIB_HT
  344. void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
  345. struct txentry_desc *txdesc,
  346. const struct rt2x00_rate *hwrate);
  347. #else
  348. static inline void rt2x00ht_create_tx_descriptor(struct queue_entry *entry,
  349. struct txentry_desc *txdesc,
  350. const struct rt2x00_rate *hwrate)
  351. {
  352. }
  353. #endif /* CONFIG_RT2X00_LIB_HT */
  354. /*
  355. * RFkill handlers.
  356. */
  357. static inline void rt2x00rfkill_register(struct rt2x00_dev *rt2x00dev)
  358. {
  359. if (test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
  360. wiphy_rfkill_start_polling(rt2x00dev->hw->wiphy);
  361. }
  362. static inline void rt2x00rfkill_unregister(struct rt2x00_dev *rt2x00dev)
  363. {
  364. if (test_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags))
  365. wiphy_rfkill_stop_polling(rt2x00dev->hw->wiphy);
  366. }
  367. /*
  368. * LED handlers
  369. */
  370. #ifdef CONFIG_RT2X00_LIB_LEDS
  371. void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev, int rssi);
  372. void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev, bool enabled);
  373. void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev, bool enabled);
  374. void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev, bool enabled);
  375. void rt2x00leds_register(struct rt2x00_dev *rt2x00dev);
  376. void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev);
  377. void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev);
  378. void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev);
  379. #else
  380. static inline void rt2x00leds_led_quality(struct rt2x00_dev *rt2x00dev,
  381. int rssi)
  382. {
  383. }
  384. static inline void rt2x00led_led_activity(struct rt2x00_dev *rt2x00dev,
  385. bool enabled)
  386. {
  387. }
  388. static inline void rt2x00leds_led_assoc(struct rt2x00_dev *rt2x00dev,
  389. bool enabled)
  390. {
  391. }
  392. static inline void rt2x00leds_led_radio(struct rt2x00_dev *rt2x00dev,
  393. bool enabled)
  394. {
  395. }
  396. static inline void rt2x00leds_register(struct rt2x00_dev *rt2x00dev)
  397. {
  398. }
  399. static inline void rt2x00leds_unregister(struct rt2x00_dev *rt2x00dev)
  400. {
  401. }
  402. static inline void rt2x00leds_suspend(struct rt2x00_dev *rt2x00dev)
  403. {
  404. }
  405. static inline void rt2x00leds_resume(struct rt2x00_dev *rt2x00dev)
  406. {
  407. }
  408. #endif /* CONFIG_RT2X00_LIB_LEDS */
  409. #endif /* RT2X00LIB_H */