rt2800lib.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. Copyright (C) 2010 Willow Garage <http://www.willowgarage.com>
  4. Copyright (C) 2010 Ivo van Doorn <[email protected]>
  5. Copyright (C) 2009 Bartlomiej Zolnierkiewicz
  6. */
  7. #ifndef RT2800LIB_H
  8. #define RT2800LIB_H
  9. /*
  10. * Hardware has 255 WCID table entries. First 32 entries are reserved for
  11. * shared keys. Since parts of the pairwise key table might be shared with
  12. * the beacon frame buffers 6 & 7 we could only use the first 222 entries.
  13. */
  14. #define WCID_START 33
  15. #define WCID_END 222
  16. #define STA_IDS_SIZE (WCID_END - WCID_START + 2)
  17. #define CHAIN_0 0x0
  18. #define CHAIN_1 0x1
  19. #define RF_ALC_NUM 6
  20. #define CHAIN_NUM 2
  21. struct rf_reg_pair {
  22. u8 bank;
  23. u8 reg;
  24. u8 value;
  25. };
  26. /* RT2800 driver data structure */
  27. struct rt2800_drv_data {
  28. u8 calibration_bw20;
  29. u8 calibration_bw40;
  30. s8 rx_calibration_bw20;
  31. s8 rx_calibration_bw40;
  32. s8 tx_calibration_bw20;
  33. s8 tx_calibration_bw40;
  34. u8 bbp25;
  35. u8 bbp26;
  36. u8 txmixer_gain_24g;
  37. u8 txmixer_gain_5g;
  38. u8 max_psdu;
  39. unsigned int tbtt_tick;
  40. unsigned int ampdu_factor_cnt[4];
  41. DECLARE_BITMAP(sta_ids, STA_IDS_SIZE);
  42. struct ieee80211_sta *wcid_to_sta[STA_IDS_SIZE];
  43. };
  44. struct rt2800_ops {
  45. u32 (*register_read)(struct rt2x00_dev *rt2x00dev,
  46. const unsigned int offset);
  47. u32 (*register_read_lock)(struct rt2x00_dev *rt2x00dev,
  48. const unsigned int offset);
  49. void (*register_write)(struct rt2x00_dev *rt2x00dev,
  50. const unsigned int offset, u32 value);
  51. void (*register_write_lock)(struct rt2x00_dev *rt2x00dev,
  52. const unsigned int offset, u32 value);
  53. void (*register_multiread)(struct rt2x00_dev *rt2x00dev,
  54. const unsigned int offset,
  55. void *value, const u32 length);
  56. void (*register_multiwrite)(struct rt2x00_dev *rt2x00dev,
  57. const unsigned int offset,
  58. const void *value, const u32 length);
  59. int (*regbusy_read)(struct rt2x00_dev *rt2x00dev,
  60. const unsigned int offset,
  61. const struct rt2x00_field32 field, u32 *reg);
  62. int (*read_eeprom)(struct rt2x00_dev *rt2x00dev);
  63. bool (*hwcrypt_disabled)(struct rt2x00_dev *rt2x00dev);
  64. int (*drv_write_firmware)(struct rt2x00_dev *rt2x00dev,
  65. const u8 *data, const size_t len);
  66. int (*drv_init_registers)(struct rt2x00_dev *rt2x00dev);
  67. __le32 *(*drv_get_txwi)(struct queue_entry *entry);
  68. unsigned int (*drv_get_dma_done)(struct data_queue *queue);
  69. };
  70. static inline u32 rt2800_register_read(struct rt2x00_dev *rt2x00dev,
  71. const unsigned int offset)
  72. {
  73. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  74. return rt2800ops->register_read(rt2x00dev, offset);
  75. }
  76. static inline u32 rt2800_register_read_lock(struct rt2x00_dev *rt2x00dev,
  77. const unsigned int offset)
  78. {
  79. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  80. return rt2800ops->register_read_lock(rt2x00dev, offset);
  81. }
  82. static inline void rt2800_register_write(struct rt2x00_dev *rt2x00dev,
  83. const unsigned int offset,
  84. u32 value)
  85. {
  86. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  87. rt2800ops->register_write(rt2x00dev, offset, value);
  88. }
  89. static inline void rt2800_register_write_lock(struct rt2x00_dev *rt2x00dev,
  90. const unsigned int offset,
  91. u32 value)
  92. {
  93. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  94. rt2800ops->register_write_lock(rt2x00dev, offset, value);
  95. }
  96. static inline void rt2800_register_multiread(struct rt2x00_dev *rt2x00dev,
  97. const unsigned int offset,
  98. void *value, const u32 length)
  99. {
  100. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  101. rt2800ops->register_multiread(rt2x00dev, offset, value, length);
  102. }
  103. static inline void rt2800_register_multiwrite(struct rt2x00_dev *rt2x00dev,
  104. const unsigned int offset,
  105. const void *value,
  106. const u32 length)
  107. {
  108. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  109. rt2800ops->register_multiwrite(rt2x00dev, offset, value, length);
  110. }
  111. static inline int rt2800_regbusy_read(struct rt2x00_dev *rt2x00dev,
  112. const unsigned int offset,
  113. const struct rt2x00_field32 field,
  114. u32 *reg)
  115. {
  116. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  117. return rt2800ops->regbusy_read(rt2x00dev, offset, field, reg);
  118. }
  119. static inline int rt2800_read_eeprom(struct rt2x00_dev *rt2x00dev)
  120. {
  121. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  122. return rt2800ops->read_eeprom(rt2x00dev);
  123. }
  124. static inline bool rt2800_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
  125. {
  126. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  127. return rt2800ops->hwcrypt_disabled(rt2x00dev);
  128. }
  129. static inline int rt2800_drv_write_firmware(struct rt2x00_dev *rt2x00dev,
  130. const u8 *data, const size_t len)
  131. {
  132. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  133. return rt2800ops->drv_write_firmware(rt2x00dev, data, len);
  134. }
  135. static inline int rt2800_drv_init_registers(struct rt2x00_dev *rt2x00dev)
  136. {
  137. const struct rt2800_ops *rt2800ops = rt2x00dev->ops->drv;
  138. return rt2800ops->drv_init_registers(rt2x00dev);
  139. }
  140. static inline __le32 *rt2800_drv_get_txwi(struct queue_entry *entry)
  141. {
  142. const struct rt2800_ops *rt2800ops = entry->queue->rt2x00dev->ops->drv;
  143. return rt2800ops->drv_get_txwi(entry);
  144. }
  145. static inline unsigned int rt2800_drv_get_dma_done(struct data_queue *queue)
  146. {
  147. const struct rt2800_ops *rt2800ops = queue->rt2x00dev->ops->drv;
  148. return rt2800ops->drv_get_dma_done(queue);
  149. }
  150. void rt2800_mcu_request(struct rt2x00_dev *rt2x00dev,
  151. const u8 command, const u8 token,
  152. const u8 arg0, const u8 arg1);
  153. int rt2800_wait_csr_ready(struct rt2x00_dev *rt2x00dev);
  154. int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev);
  155. int rt2800_check_firmware(struct rt2x00_dev *rt2x00dev,
  156. const u8 *data, const size_t len);
  157. int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
  158. const u8 *data, const size_t len);
  159. void rt2800_write_tx_data(struct queue_entry *entry,
  160. struct txentry_desc *txdesc);
  161. void rt2800_process_rxwi(struct queue_entry *entry, struct rxdone_entry_desc *txdesc);
  162. void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
  163. bool match);
  164. void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
  165. void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
  166. bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
  167. bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
  168. void rt2800_watchdog(struct rt2x00_dev *rt2x00dev);
  169. void rt2800_write_beacon(struct queue_entry *entry, struct txentry_desc *txdesc);
  170. void rt2800_clear_beacon(struct queue_entry *entry);
  171. extern const struct rt2x00debug rt2800_rt2x00debug;
  172. int rt2800_rfkill_poll(struct rt2x00_dev *rt2x00dev);
  173. int rt2800_config_shared_key(struct rt2x00_dev *rt2x00dev,
  174. struct rt2x00lib_crypto *crypto,
  175. struct ieee80211_key_conf *key);
  176. int rt2800_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
  177. struct rt2x00lib_crypto *crypto,
  178. struct ieee80211_key_conf *key);
  179. int rt2800_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  180. struct ieee80211_sta *sta);
  181. int rt2800_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  182. struct ieee80211_sta *sta);
  183. void rt2800_config_filter(struct rt2x00_dev *rt2x00dev,
  184. const unsigned int filter_flags);
  185. void rt2800_config_intf(struct rt2x00_dev *rt2x00dev, struct rt2x00_intf *intf,
  186. struct rt2x00intf_conf *conf, const unsigned int flags);
  187. void rt2800_config_erp(struct rt2x00_dev *rt2x00dev, struct rt2x00lib_erp *erp,
  188. u32 changed);
  189. void rt2800_config_ant(struct rt2x00_dev *rt2x00dev, struct antenna_setup *ant);
  190. void rt2800_config(struct rt2x00_dev *rt2x00dev,
  191. struct rt2x00lib_conf *libconf,
  192. const unsigned int flags);
  193. void rt2800_link_stats(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
  194. void rt2800_reset_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual);
  195. void rt2800_link_tuner(struct rt2x00_dev *rt2x00dev, struct link_qual *qual,
  196. const u32 count);
  197. void rt2800_gain_calibration(struct rt2x00_dev *rt2x00dev);
  198. void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev);
  199. int rt2800_enable_radio(struct rt2x00_dev *rt2x00dev);
  200. void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev);
  201. int rt2800_efuse_detect(struct rt2x00_dev *rt2x00dev);
  202. int rt2800_read_eeprom_efuse(struct rt2x00_dev *rt2x00dev);
  203. int rt2800_probe_hw(struct rt2x00_dev *rt2x00dev);
  204. void rt2800_get_key_seq(struct ieee80211_hw *hw,
  205. struct ieee80211_key_conf *key,
  206. struct ieee80211_key_seq *seq);
  207. int rt2800_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
  208. int rt2800_conf_tx(struct ieee80211_hw *hw,
  209. struct ieee80211_vif *vif,
  210. unsigned int link_id, u16 queue_idx,
  211. const struct ieee80211_tx_queue_params *params);
  212. u64 rt2800_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
  213. int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  214. struct ieee80211_ampdu_params *params);
  215. int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
  216. struct survey_info *survey);
  217. void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
  218. void rt2800_get_txwi_rxwi_size(struct rt2x00_dev *rt2x00dev,
  219. unsigned short *txwi_size,
  220. unsigned short *rxwi_size);
  221. void rt2800_pre_reset_hw(struct rt2x00_dev *rt2x00dev);
  222. #endif /* RT2800LIB_H */