rt2x00lib.h 13 KB

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